18 #if !defined(__clang__) 31 inline bool operator<(
const uint128 & a,
const uint128 & b) noexcept;
32 inline bool operator==(
const uint128 & a,
const uint128 & b) noexcept;
33 inline bool operator||(
const uint128 & a,
const uint128 & b) noexcept;
34 inline bool operator&&(
const uint128 & a,
const uint128 & b) noexcept;
38 inline uint128
operator+(
const uint128 & a,
const uint128 & b) noexcept;
39 inline uint128
operator-(
const uint128 & a,
const uint128 & b) noexcept;
40 inline uint128
operator*(
const uint128 & a,
const uint128 & b) noexcept;
41 inline uint128 operator/(
const uint128 & a,
const uint128 & b) noexcept;
42 inline uint128 operator%(
const uint128 & a,
const uint128 & b) noexcept;
44 inline uint128 operator>>(
const uint128 & a,
unsigned int n) noexcept;
45 inline uint128
operator<<(
const uint128 & a,
unsigned int n) noexcept;
47 inline uint128 operator&(
const uint128 & a,
const uint128 & b) noexcept;
48 inline uint128 operator|(
const uint128 & a,
const uint128 & b) noexcept;
49 inline uint128 operator^(
const uint128 & a,
const uint128 & b) noexcept;
51 inline bool operator>(
const uint128 & a,
const uint128 & b) noexcept;
52 inline bool operator<=(
const uint128 & a,
const uint128 & b) noexcept;
53 inline bool operator>=(
const uint128 & a,
const uint128 & b) noexcept;
54 inline bool operator!=(
const uint128 & a,
const uint128 & b) noexcept;
73 inline uint128() noexcept : lo(0ull), hi(0ull) {}
75 inline uint128(
int a) noexcept : lo(a), hi(0ull) {}
76 inline uint128(
unsigned int a) noexcept : lo(a), hi(0ull) {}
77 inline uint128(std::uint64_t a) noexcept : lo(a), hi(0ull) {}
80 : lo((std::uint64_t)fmodf(a, 18446744073709551616.0f)),
81 hi((std::uint64_t)(a / 18446744073709551616.0f)) {}
83 : lo((std::uint64_t)fmod(a, 18446744073709551616.0)),
84 hi((std::uint64_t)(a / 18446744073709551616.0)) {}
86 : lo((std::uint64_t)fmodl(a, 18446744073709551616.0l)),
87 hi((std::uint64_t)(a / 18446744073709551616.0l)) {}
89 uint128(
const char * sz) noexcept : lo(0u), hi(0u) {
95 unsigned int radix = 10;
113 std::size_t len = strlen(sz);
114 for(; i < len; ++i) {
116 if(sz[i] >=
'0' && sz[i] <= (std::min)((
'0' + (
int)radix), (
int)
'9'))
118 else if(sz[i] >=
'a' && sz[i] <=
'a' + (
int)radix - 10)
119 n = sz[i] -
'a' + 10;
120 else if(sz[i] >=
'A' && sz[i] <=
'A' + (
int)radix - 10)
121 n = sz[i] -
'A' + 10;
138 uint128(
const std::uint64_t & a,
const std::uint64_t & b) noexcept
143 bool operator!()
const noexcept {
144 return !(this->hi || this->lo);
147 uint128 operator-()
const noexcept {
148 if(!this->hi && !this->lo)
152 #pragma warning(push) 153 #pragma warning(disable : 4146) 155 return uint128(-this->lo, ~this->hi);
158 uint128 operator~()
const noexcept {
159 return uint128(~this->lo, ~this->hi);
190 std::uint64_t old_lo = this->lo;
193 this->hi += b.hi + (this->lo < old_lo);
209 for(
unsigned int i = 0; i < 128; ++i) {
219 uint128 & operator>>=(
unsigned int n) noexcept {
233 std::uint64_t mask = 0ull;
234 for(
unsigned int i = 0; i < n; ++i)
238 this->lo |= (this->hi & mask) << (64 - n);
246 uint128 & operator<<=(
unsigned int n) noexcept {
260 std::uint64_t mask = 0ull;
261 for(
unsigned int i = 0; i < n; ++i)
262 mask |= (1ll << (63 - i));
265 this->hi |= (this->lo & mask) >> (64 - n);
293 explicit operator bool()
const noexcept {
298 inline const uint128 & operator+()
const noexcept {
304 return *
this += (-b);
308 *
this = this->div(b, dummy);
316 explicit operator std::uint64_t()
const noexcept {
321 unsigned int toUint()
const noexcept {
322 return (
unsigned int)this->lo;
324 std::uint64_t toUint64()
const noexcept {
325 return (std::uint64_t)this->lo;
327 const char * toString(
unsigned int radix = 10)
const noexcept {
330 if(radix < 2 || radix > 37)
331 return "(invalid radix)";
334 std::memset(sz, 0, 256);
341 ii = ii.div(radix, r);
342 sz[--i] = r.toUint() + ((r.toUint() > 9) ?
'A' - 10 :
'0');
347 float toFloat()
const noexcept {
348 return (
float)this->hi * 18446744073709551616.0f + (float)this->lo;
350 double toDouble()
const noexcept {
351 return (
double)this->hi * 18446744073709551616.0 + (double)this->lo;
353 long double toLongDouble()
const noexcept {
354 return (
long double)this->hi * 18446744073709551616.0l +
355 (
long double)this->lo;
361 return 1u / (
unsigned int)ds.lo;
368 return std::uint64_t(0ull);
371 uint128 r = std::uint64_t(0ull);
372 uint128 q = std::uint64_t(0ull);
375 unsigned int b = 127;
402 bool bit(
unsigned int n)
const noexcept {
406 return (this->lo & (1ull << n)) ? true :
false;
408 return (this->hi & (1ull << (n - 64))) ? true :
false;
410 void bit(
unsigned int n,
bool val) noexcept {
415 this->lo |= (1ull << n);
417 this->hi |= (1ull << (n - 64));
421 this->lo &= ~(1ull << n);
423 this->hi &= ~(1ull << (n - 64));
428 __attribute__((__aligned__(16), __packed__))
436 return (a.hi == b.hi) ? (a.lo < b.lo) : (a.hi < b.hi);
440 return a.hi == b.hi && a.lo == b.lo;
444 return (a.hi || a.lo) && (b.hi || b.lo);
448 return (a.hi || a.lo) || (b.hi || b.lo);
474 operator>>(
const uint128 & a,
unsigned int n) noexcept {
Definition: uint128.hh:57
constexpr dimensioned_array< TYPE, DIMENSION, NAMESPACE > operator+(const dimensioned_array< TYPE, DIMENSION, NAMESPACE > &lhs, const dimensioned_array< TYPE, DIMENSION, NAMESPACE > &rhs)
Definition: dimensioned_array.hh:261
std::ostream & operator<<(std::ostream &ostr, const filling_curve< D, T, DER > &k)
output for filling_curve using output_ function defined in the class
Definition: filling_curve.hh:206
constexpr point< TYPE, DIMENSION > operator*(TYPE const val, point< TYPE, DIMENSION > const &p)
Definition: point.hh:52
constexpr dimensioned_array< TYPE, DIMENSION, NAMESPACE > operator-(const dimensioned_array< TYPE, DIMENSION, NAMESPACE > &lhs, const dimensioned_array< TYPE, DIMENSION, NAMESPACE > &rhs)
Definition: dimensioned_array.hh:281
Definition: control.hh:31