25 return (negA && !negB) || (!negA && negB);
34 _v = negative ? -result : result;
55 midPart = aL * bH + aH * bL;
60 "High precision 128 bits multiplication error: multiplication overflow.");
83 _v = negative ? -result : result;
97 const uint64_t DIGITS = 64;
101 "Remainder not less than divisor");
107 while ( (shift < DIGITS) && !(den & 0x1))
113 while ( (digis < DIGITS) && (rem != ZERO) )
116 while ( (digis + shift < DIGITS) &&
127 while ( (digis + shift < DIGITS) &&
128 ( !(den & 0x1) || (rem < den) ) )
148 shift = DIGITS - digis;
158 bool negResult =
_v < 0;
162 _v = negResult ? -result : result;
175 mid = ah * bl + al * bh;
High precision numerical type, implementing Q64.64 fixed precision.
static uint128_t Udiv(const uint128_t a, const uint128_t b)
Unsigned division of Q64.64 values.
static int64x64_t Invert(const uint64_t v)
Compute the inverse of an integer value.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
static uint128_t UmulByInvert(const uint128_t a, const uint128_t b)
Unsigned multiplication of Q64.64 and Q0.128 values.
static uint128_t Umul(const uint128_t a, const uint128_t b)
Unsigned multiplication of Q64.64 values.
int128_t _v
The Q64.64 value.
void Mul(const int64x64_t &o)
Implement *=.
int64x64_t()
Default constructor.
static bool output_sign(const int128_t sa, const int128_t sb, uint128_t &ua, uint128_t &ub)
static const uint128_t HP128_MASK_HI_BIT
uint128_t high bit (sign bit)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
static const uint64_t HP_MASK_LO
Mask for fraction part.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if cond is true.
void Div(const int64x64_t &o)
Implement /=.
int64_t GetHigh(void) const
Get the integer portion.
static const uint64_t HP_MASK_HI
Mask for sign + integer part.