#pragma once #include /* 48.16, with bad overflowing mul & div. */ class fixed { public: enum { FRAC = 16 }; fixed(void) : v(0) {} fixed(Sint64 raw) : v(raw) {} fixed(Sint64 num, Sint64 denom) : v((num<=(const fixed a, const int b) { return a >= fixed(b<=(const int a, const fixed b) { return b >= fixed(a<(const fixed a, const int b) { return a > fixed(b<(const int a, const fixed b) { return b > fixed(a<>(const fixed a, const int b) { return fixed(a.v >> b); } friend fixed operator<<(const fixed a, const int b) { return fixed(a.v << b); } fixed &operator*=(const fixed a) { (*this) = (*this)*a; return (*this); } fixed &operator*=(const int a) { (*this) = (*this)*a; return (*this); } fixed &operator/=(const fixed a) { (*this) = (*this)/a; return (*this); } fixed &operator/=(const int a) { (*this) = (*this)/a; return (*this); } fixed &operator+=(const fixed a) { (*this) = (*this)+a; return (*this); } fixed &operator+=(const int a) { (*this) = (*this)+a; return (*this); } fixed &operator-=(const fixed a) { (*this) = (*this)-a; return (*this); } fixed &operator-=(const int a) { (*this) = (*this)-a; return (*this); } fixed &operator>>=(const int a) { v >>= a; return (*this); } fixed &operator<<=(const int a) { v <<= a; return (*this); } friend fixed operator+(const fixed a, const fixed b) { return fixed(a.v+b.v); } friend fixed operator-(const fixed a, const fixed b) { return fixed(a.v-b.v); } friend fixed operator*(const fixed a, const fixed b) { return fixed((a.v*b.v)>>FRAC); } friend fixed operator/(const fixed a, const fixed b) { return fixed((a.v<(const fixed a, const fixed b) { return a.v > b.v; } friend bool operator<(const fixed a, const fixed b) { return a.v < b.v; } friend bool operator>=(const fixed a, const fixed b) { return a.v >= b.v; } friend bool operator<=(const fixed a, const fixed b) { return a.v <= b.v; } /* Implicit operator float() is bad. */ Sint64 ToInt64(void) const { return v>>FRAC; } float ToFloat(void) const { return v/(float)(1<