28 constexpr QFixed(
int val,
int) : val(val) {}
30 constexpr QFixed() : val(0) {}
31 constexpr QFixed(
int i) : val(i * 64) {}
32 constexpr QFixed(
long i) : val(i * 64) {}
33 constexpr QFixed(
long long i) : val(i * 64) {}
35 constexpr static QFixed fromReal(qreal r) {
return fromFixed((
int)(r*qreal(64))); }
36 constexpr static QFixed fromFixed(
int fixed) {
return QFixed(fixed,0); }
38 constexpr inline int value()
const {
return val; }
39 inline void setValue(
int value) { val = value; }
41 constexpr inline int toInt()
const {
return (((val)+32) & -64)>>6; }
42 constexpr inline qreal toReal()
const {
return ((qreal)val)/(qreal)64; }
44 constexpr inline int truncate()
const {
return val>>6; }
45 constexpr inline QFixed round()
const {
return fromFixed(((val)+32) & -64); }
46 constexpr inline QFixed floor()
const {
return fromFixed((val) & -64); }
47 constexpr inline QFixed ceil()
const {
return fromFixed((val+63) & -64); }
49 constexpr inline QFixed operator+(
int i)
const {
return fromFixed(val + i * 64); }
50 constexpr inline QFixed operator+(uint i)
const {
return fromFixed((val + (i<<6))); }
51 constexpr inline QFixed operator+(QFixed other)
const {
return fromFixed((val + other.val)); }
52 inline QFixed &operator+=(
int i) { val += i * 64;
return *
this; }
53 inline QFixed &operator+=(uint i) { val += (i<<6);
return *
this; }
54 inline QFixed &operator+=(QFixed other) { val += other.val;
return *
this; }
55 constexpr inline QFixed operator-(
int i)
const {
return fromFixed(val - i * 64); }
56 constexpr inline QFixed operator-(uint i)
const {
return fromFixed((val - (i<<6))); }
57 constexpr inline QFixed operator-(QFixed other)
const {
return fromFixed((val - other.val)); }
58 inline QFixed &operator-=(
int i) { val -= i * 64;
return *
this; }
59 inline QFixed &operator-=(uint i) { val -= (i<<6);
return *
this; }
60 inline QFixed &operator-=(QFixed other) { val -= other.val;
return *
this; }
61 constexpr inline QFixed operator-()
const {
return fromFixed(-val); }
64 friend constexpr bool operator
op(QFixed lhs, QFixed rhs) noexcept
65 { return lhs.val op rhs.val; }
74 constexpr inline bool operator!()
const {
return !val; }
76 inline QFixed &operator/=(
int x) { val /= x;
return *
this; }
77 inline QFixed &operator/=(QFixed o) {
84 if (a < 0) { a = -a; neg =
true; }
85 if (b < 0) { b = -b; neg = !neg; }
87 int res = (
int)(((a << 6) + (b >> 1)) / b);
89 val = (neg ? -res : res);
93 constexpr inline QFixed operator/(
int d)
const {
return fromFixed(val/d); }
94 inline QFixed operator/(QFixed b)
const { QFixed f = *
this;
return (f /= b); }
95 inline QFixed operator>>(
int d)
const { QFixed f = *
this; f.val >>= d;
return f; }
96 inline QFixed &operator*=(
int i) { val *= i;
return *
this; }
97 inline QFixed &operator*=(uint i) { val *= i;
return *
this; }
98 inline QFixed &operator*=(QFixed o) {
102 if (a < 0) { a = -a; neg =
true; }
103 if (b < 0) { b = -b; neg = !neg; }
105 int res = (
int)((a * b + 0x20L) >> 6);
106 val = neg ? -res : res;
109 constexpr inline QFixed operator*(
int i)
const {
return fromFixed(val * i); }
110 constexpr inline QFixed operator*(uint i)
const {
return fromFixed(val * i); }
111 inline QFixed operator*(QFixed o)
const { QFixed f = *
this;
return (f *= o); }
114 constexpr QFixed(qreal i) : val((
int)(i*qreal(64))) {}
115 constexpr inline QFixed operator+(qreal i)
const {
return fromFixed((val + (
int)(i*qreal(64)))); }
116 inline QFixed &operator+=(qreal i) { val += (
int)(i*64);
return *
this; }
117 constexpr inline QFixed operator-(qreal i)
const {
return fromFixed((val - (
int)(i*qreal(64)))); }
118 inline QFixed &operator-=(qreal i) { val -= (
int)(i*64);
return *
this; }
119 inline QFixed &operator/=(qreal r) { val = (
int)(val/r);
return *
this; }
120 constexpr inline QFixed operator/(qreal d)
const {
return fromFixed((
int)(val/d)); }
121 inline QFixed &operator*=(qreal d) { val = (
int) (val*d);
return *
this; }
122 constexpr inline QFixed operator*(qreal d)
const {
return fromFixed((
int) (val*d)); }