summaryrefslogtreecommitdiff
path: root/src/fixed_point.cpp
blob: 847a5f72734dbfb9d2b8ded5c4a9534c62df3513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "fixed_point.h"

fp_t fp_t::operator+(const fp_t& other) const {
    return {(int32_t)((uint32_t)raw + (uint32_t)other.raw)};
}

fp_t fp_t::operator-(const fp_t& other) const {
    return {(int32_t)((uint32_t)raw - (uint32_t)other.raw)};
}

fp_t fp_t::operator*(const fp_t& other) const {
    int32_t result;
    int64_t temp;
    temp = (int64_t)raw * (int64_t)other.raw;
    temp += fp_t::K;
    result = (int32_t)(temp >> fp_t::Q);
    return {result};
}

bool fp_t::operator==(const fp_t& other) const {
    return raw == other.raw;
}