10template <
int FRAC_BITS>
13 static const int FRAC = FRAC_BITS;
14 static const Uint64
MASK = (Uint64(1UL) << FRAC_BITS) - 1;
22 constexpr fixedf(Sint64 num, Sint64 denom) :
23 v((num <<
FRAC) / denom) {}
52 (*this) = (*this) * a;
57 (*this) = (*this) * a;
62 (*this) = (*this) / a;
67 (*this) = (*this) / a;
72 (*this) = (*this) + a;
77 (*this) = (*this) + a;
82 (*this) = (*this) - a;
87 (*this) = (*this) - a;
109 Uint64 a0, a1, b0, b1;
114 a0 = (-a.
v) & 0xffffffff;
118 a0 = a.
v & 0xffffffff;
122 b0 = (-b.
v) & 0xffffffff;
126 b0 = b.
v & 0xffffffff;
135 if (lo < oldlo) hi++;
142 if (lo < oldlo) hi++;
147 Sint64 out = (lo >>
FRAC) + ((hi &
MASK) << (64 -
FRAC));
148 return isneg ? -out : out;
153 Sint64 quotient_hi = a.
v >> (64 -
FRAC);
154 Uint64 quotient_lo = a.
v <<
FRAC;
157 Sint64 remainder = 0;
164 for (
int i = 0; i < 128; i++) {
165 Uint64 sbit = (Uint64(1) << 63) & quotient_hi;
167 if (sbit) remainder |= 1;
171 if (quotient_lo & (Uint64(1) << 63)) quotient_hi |= 1;
174 if (remainder >= d) {
179 return (isneg ? -Sint64(quotient_lo) : quotient_lo);
196 template <
int NEW_FRAC_BITS>
199 int shift = NEW_FRAC_BITS - FRAC_BITS;
210 Uint64 root, remHi, remLo, testDiv, count;
214 count = 32 + (
FRAC >> 1) - 1;
216 remHi = (remHi << 2) | (remLo >> 62);
219 testDiv = (root << 1) + 1;
220 if (remHi >= testDiv) {
224 }
while (count-- != 0);
234 for (
int i = 0; i < 48; i++)
235 x =
fixedf(1, 3) * ((a / (x * x)) + 2 * x);
double val
Definition PrecalcPath.cpp:40
static fixedf CubeRootOf(const fixedf &a)
Definition fixed.h:229
friend fixedf operator+(const fixedf &a, const fixedf &b)
Definition fixed.h:102
fixedf & operator-=(const Sint64 a)
Definition fixed.h:85
friend bool operator<=(const Sint64 a, const fixedf &b)
Definition fixed.h:42
friend fixedf operator+(const Sint64 a, const fixedf &b)
Definition fixed.h:31
friend fixedf operator<<(const fixedf &a, const int b)
Definition fixed.h:48
friend fixedf operator/(const Sint64 a, const fixedf &b)
Definition fixed.h:34
fixedf & operator*=(const Sint64 a)
Definition fixed.h:55
Sint64 v
Definition fixed.h:239
static fixedf SqrtOf(const fixedf &a)
Definition fixed.h:206
friend fixedf operator/(const fixedf &a, const Sint64 b)
Definition fixed.h:30
int ToInt32() const
Definition fixed.h:189
friend bool operator>=(const fixedf &a, const Sint64 b)
Definition fixed.h:39
friend bool operator<(const fixedf &a, const fixedf &b)
Definition fixed.h:184
friend bool operator!=(const fixedf &a, const fixedf &b)
Definition fixed.h:182
friend fixedf operator-(const fixedf &a)
Definition fixed.h:101
friend bool operator>(const fixedf &a, const Sint64 b)
Definition fixed.h:43
constexpr fixedf(Sint64 raw)
Definition fixed.h:20
fixedf & operator<<=(const int a)
Definition fixed.h:95
fixedf & operator>>=(const int a)
Definition fixed.h:90
fixedf & operator/=(const fixedf &a)
Definition fixed.h:60
fixedf & operator-=(const fixedf &a)
Definition fixed.h:80
friend bool operator<(const Sint64 a, const fixedf &b)
Definition fixed.h:46
friend bool operator<=(const fixedf &a, const Sint64 b)
Definition fixed.h:41
friend bool operator==(const fixedf &a, const Sint64 b)
Definition fixed.h:35
friend fixedf operator-(const Sint64 a, const fixedf &b)
Definition fixed.h:32
fixedf & operator+=(const Sint64 a)
Definition fixed.h:75
friend fixedf operator>>(const fixedf &a, const int b)
Definition fixed.h:47
friend bool operator==(const fixedf &a, const fixedf &b)
Definition fixed.h:181
friend bool operator==(const Sint64 a, const fixedf &b)
Definition fixed.h:36
fixedf Abs() const
Definition fixed.h:26
friend fixedf operator/(const fixedf &a, const fixedf &b)
Definition fixed.h:150
float ToFloat() const
Definition fixed.h:191
fixedf()
Definition fixed.h:16
static fixedf FromDouble(const double val)
Definition fixed.h:194
friend fixedf operator-(const fixedf &a, const fixedf &b)
Definition fixed.h:103
static const Uint64 MASK
Definition fixed.h:14
fixedf & operator+=(const fixedf &a)
Definition fixed.h:70
friend bool operator>(const Sint64 a, const fixedf &b)
Definition fixed.h:44
friend fixedf operator+(const fixedf &a, const Sint64 b)
Definition fixed.h:27
constexpr fixedf(Sint64 num, Sint64 denom)
Definition fixed.h:22
fixedf & operator/=(const Sint64 a)
Definition fixed.h:65
friend fixedf operator*(const Sint64 a, const fixedf &b)
Definition fixed.h:33
friend fixedf operator*(const fixedf &a, const fixedf &b)
Definition fixed.h:104
friend bool operator!=(const fixedf &a, const Sint64 b)
Definition fixed.h:37
friend bool operator>=(const fixedf &a, const fixedf &b)
Definition fixed.h:185
static const int FRAC
Definition fixed.h:13
friend bool operator!=(const Sint64 a, const fixedf &b)
Definition fixed.h:38
friend fixedf operator-(const fixedf &a, const Sint64 b)
Definition fixed.h:28
friend bool operator>=(const Sint64 a, const fixedf &b)
Definition fixed.h:40
Sint64 ToInt64() const
Definition fixed.h:190
friend bool operator<(const fixedf &a, const Sint64 b)
Definition fixed.h:45
friend bool operator<=(const fixedf &a, const fixedf &b)
Definition fixed.h:186
fixedf & operator*=(const fixedf &a)
Definition fixed.h:50
friend bool operator>(const fixedf &a, const fixedf &b)
Definition fixed.h:183
friend fixedf operator*(const fixedf &a, const Sint64 b)
Definition fixed.h:29
double ToDouble() const
Definition fixed.h:192
fixedf< 32 > fixed
Definition fixed.h:242