28 #ifndef __STDC_LIMIT_MACROS 29 #define __STDC_LIMIT_MACROS 1 31 #ifndef __STDC_CONSTANT_MACROS 32 #define __STDC_CONSTANT_MACROS 1 34 #ifndef __STDC_FORMAT_MACROS 35 #define __STDC_FORMAT_MACROS 1 42 #include <type_traits> 67 static const unsigned int flagbits = 3;
68 static const unsigned int numlegs = 2;
69 static const unsigned int legbits = 64;
70 static const unsigned int maxbits = legbits * numlegs - flagbits;
91 std::enable_if_t<std::is_integral<T>::value,
bool> =
true>
97 template <
typename T,
typename U,
98 std::enable_if_t<(std::is_integral<T>::value &&
99 std::is_integral<U>::value),
bool> =
true>
100 GncInt128(T upper, U lower,
unsigned char flags =
'\0') :
102 static_cast<int64_t>(lower), flags} {}
104 GncInt128 (int64_t upper, int64_t lower,
unsigned char flags =
'\0');
105 template <
typename T,
106 std::enable_if_t<std::is_integral<T>::value,
bool> =
true>
108 GncInt128 {
static_cast<int64_t
>(upper), lower} {}
110 GncInt128 (int64_t upper, uint64_t lower,
unsigned char flags =
'\0');
111 GncInt128 (uint64_t upper, uint64_t lower,
unsigned char flags =
'\0');
169 explicit operator int64_t() const;
177 explicit operator uint64_t() const;
182 bool isNeg () const noexcept;
186 bool isBig () const noexcept;
195 bool isNan () const noexcept;
199 bool isZero() const noexcept;
203 bool valid() const noexcept;
208 unsigned int bits() const noexcept;
218 char*
asCharBufR(
char* buf, uint32_t size) const noexcept;
223 explicit operator
bool() const noexcept;
229 GncInt128& operator<<= (
unsigned int i) noexcept;
230 GncInt128& operator>>= (
unsigned int i) noexcept;
242 static const
GncInt128 k_gncint128_Max {UINT64_MAX, UINT64_MAX, GncInt128::pos};
243 static const GncInt128 k_gncint128_Min {UINT64_MAX, UINT64_MAX, GncInt128::neg};
263 std::ostream& operator<< (std::ostream&,
const GncInt128&) noexcept;
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.
bool isNan() const noexcept
char * asCharBufR(char *buf, uint32_t size) const noexcept
Fills a supplied buffer with a representation of the number in base 10.
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
GncInt128(T upper, U lower, unsigned char flags='\0')
Double-integer constructor template.
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