30 #ifndef __STDC_LIMIT_MACROS 31 #define __STDC_LIMIT_MACROS 1 33 #ifndef __STDC_CONSTANT_MACROS 34 #define __STDC_CONSTANT_MACROS 1 36 #ifndef __STDC_FORMAT_MACROS 37 #define __STDC_FORMAT_MACROS 1 45 #include <type_traits> 70 static const unsigned int flagbits = 3;
71 static const unsigned int numlegs = 2;
72 static const unsigned int legbits = 64;
73 static const unsigned int maxbits = legbits * numlegs - flagbits;
96 static_assert (std::is_integral<T>(),
97 "GncInt128 can be constructed only with " 98 "integral arguments.");
103 template <
typename T,
typename U>
104 GncInt128(T upper, U lower,
unsigned char flags =
'\0') :
106 static_cast<int64_t>(lower), flags}
108 static_assert (std::is_integral<T>(),
109 "GncInt128 can be constructed only with " 110 "integral arguments.");
111 static_assert (std::is_integral<U>(),
112 "GncInt128 can be constructed only with " 113 "integral arguments.");
116 GncInt128 (int64_t upper, int64_t lower,
unsigned char flags =
'\0');
117 template <
typename T>
119 GncInt128 {
static_cast<int64_t
>(upper), lower}
121 static_assert (std::is_integral<T>(),
122 "GncInt128 can be constructed only with " 123 "integral arguments.");
126 GncInt128 (int64_t upper, uint64_t lower,
unsigned char flags =
'\0');
127 GncInt128 (uint64_t upper, uint64_t lower,
unsigned char flags =
'\0');
185 explicit operator int64_t() const;
193 explicit operator uint64_t() const;
198 bool isNeg () const noexcept;
202 bool isBig () const noexcept;
211 bool isNan () const noexcept;
215 bool isZero() const noexcept;
219 bool valid() const noexcept;
224 unsigned int bits() const noexcept;
239 explicit operator
bool() const noexcept;
245 GncInt128& operator<<= (
unsigned int i) noexcept;
246 GncInt128& operator>>= (
unsigned int i) noexcept;
258 static const
GncInt128 k_gncint128_Max {UINT64_MAX, UINT64_MAX, GncInt128::pos};
259 static const GncInt128 k_gncint128_Min {UINT64_MAX, UINT64_MAX, GncInt128::neg};
279 std::ostream& operator<< (std::ostream&,
const GncInt128&) noexcept;
char * asCharBufR(char *buf) const noexcept
Fills a supplied buffer with a representation of the number in base 10.
bool isBig() const noexcept
GncInt128 gcd(GncInt128 b) const noexcept
Computes the Greatest Common Divisor between the object and parameter.
GncInt128 pow(unsigned int n) const noexcept
Computes the object raised to the parameter's power.
bool valid() const noexcept
GncInt128()
Default constructor.
GncInt128(T upper, U lower, unsigned char flags='\0')
Double-integer constructor template.
bool isNan() const noexcept
bool isZero() const noexcept
GncInt128 lcm(const GncInt128 &b) const noexcept
Computes the Least Common Multiple between the object and parameter.
bool isNeg() const noexcept
void div(const GncInt128 &d, GncInt128 &q, GncInt128 &r) const noexcept
Computes a quotient and a remainder, passed as reference parameters.
int cmp(const GncInt128 &b) const noexcept
Compare function.
bool isOverflow() const noexcept
GncInt128 & zero() noexcept
Clear the object.
unsigned int bits() const noexcept