11 int i = expectedRaw >>
BITS;
12 unsigned fi = expectedRaw & ((1 <<
BITS) - 1);
13 float ff = float (fi) / (1 <<
BITS);
14 double fd = double(fi) / (1 <<
BITS);
15 float f = narrow_cast<float >(i) + ff;
16 double d = narrow_cast<double>(i) + fd;
17 CHECK(fp.toInt() == i);
18 CHECK(fp.toFloat() == f);
19 CHECK(fp.toDouble() == d);
20 CHECK(fp.fractAsInt() == fi);
21 CHECK(fp.fractionAsFloat() == ff);
22 CHECK(fp.fractionAsDouble() == fd);
23 CHECK(fp.floor().getRawValue() == (i <<
BITS));
24 CHECK(fp.fract().getRawValue() ==
int(fi));
45 check(a - b, 26); check(b - a, -26);
46 check(a - c, 33); check(c - a, -33);
47 check(b - c, 7); check(c - b, -7);
56 check(a / b, 11); check(b / a, 1);
57 check(a / c, 22); check(c / a, 0);
58 check(b / c, 8); check(c / b, 2);
63 check(a << 1, 80); check(a >> 3, 5);
64 check(b << 2, 56); check(b >> 2, 3);
65 check(c << 3, 56); check(c >> 1, 3);
75 c -= a; check(c, -47);
A fixed point number, implemented by a 32-bit signed integer.
constexpr int divAsInt(FixedPoint other) const
Returns the result of a division between this fixed point number and another, rounded towards zero.
constexpr int getRawValue() const
constexpr void addQuantum()
Increase this value with the smallest possible amount.
This file implemented 3 utility functions: