NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
int128.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_NUMERIC_INT128_HPP__
2#define NEFORCE_CORE_NUMERIC_INT128_HPP__
3
20
25NEFORCE_BEGIN_NAMESPACE__
26
27struct NEFORCE_API int128_t;
28
34
39struct NEFORCE_API uint128_t : icommon<uint128_t>, iarithmetic<uint128_t>, ibinary<uint128_t>, iobject<uint128_t> {
40public:
43
44 constexpr uint128_t() noexcept = default;
45 NEFORCE_CONSTEXPR20 ~uint128_t() = default;
46
51 constexpr uint128_t(const int32_t low) noexcept :
52 lo(static_cast<uint64_t>(static_cast<int64_t>(low))),
53 hi(low < 0 ? ~static_cast<uint64_t>(0) : 0) {}
54
59 constexpr uint128_t(const uint32_t low) noexcept :
60 lo(low) {}
61
66 constexpr uint128_t(const unsigned long low) noexcept :
67 lo(low) {}
68
73 constexpr uint128_t(const unsigned long long low) noexcept :
74 lo(low) {}
75
81 constexpr uint128_t(const uint64_t high, const uint64_t low) noexcept :
82 lo(low),
83 hi(high) {}
84
85 constexpr uint128_t(const uint128_t&) noexcept = default;
86 constexpr uint128_t& operator=(const uint128_t&) noexcept = default;
87 constexpr uint128_t(uint128_t&&) noexcept = default;
88 constexpr uint128_t& operator=(uint128_t&&) noexcept = default;
89
96 explicit NEFORCE_CONSTEXPR20 uint128_t(const string& str, int base = 10) :
97 uint128_t(str.view(), base) {}
98
105 explicit constexpr uint128_t(string_view str, int base = 10);
106
111 NEFORCE_NODISCARD constexpr int128_t to_int128() const noexcept;
112
113 explicit constexpr operator bool() const noexcept { return lo != 0U || hi != 0U; }
114 explicit constexpr operator char() const noexcept { return static_cast<char>(lo); }
115 explicit constexpr operator int8_t() const noexcept { return static_cast<int8_t>(lo); }
116 explicit constexpr operator uint8_t() const noexcept { return static_cast<uint32_t>(lo); }
117 explicit constexpr operator uint16_t() const noexcept { return static_cast<uint32_t>(lo); }
118 explicit constexpr operator uint32_t() const noexcept { return static_cast<uint32_t>(lo); }
119 explicit constexpr operator uint64_t() const noexcept { return lo; }
120 explicit constexpr operator int128_t() const noexcept;
121
125 NEFORCE_NODISCARD constexpr bool equal_to(const uint128_t& rhs) const noexcept {
126 return hi == rhs.hi && lo == rhs.lo;
127 }
128
132 NEFORCE_NODISCARD constexpr bool less_than(const uint128_t& rhs) const noexcept {
133 return hi < rhs.hi || (hi == rhs.hi && lo < rhs.lo);
134 }
135
140 constexpr uint128_t operator-() const noexcept {
141 const uint64_t new_lo = ~lo + 1ULL;
142 const uint64_t new_hi = ~hi + (lo == 0ULL ? 1ULL : 0ULL);
143 return {new_hi, new_lo};
144 }
145
149 uint128_t& operator+=(const uint128_t& other) noexcept;
150
154 uint128_t& operator-=(const uint128_t& other) noexcept;
155
159 uint128_t& operator*=(const uint128_t& other) noexcept;
160
165 uint128_t& operator/=(const uint128_t& other);
166
171 uint128_t& operator%=(const uint128_t& other);
172
176 uint128_t& operator++() noexcept {
177 *this += 1;
178 return *this;
179 }
180
184 uint128_t& operator--() noexcept {
185 *this -= 1;
186 return *this;
187 }
188
192 constexpr uint128_t operator~() const noexcept { return {~hi, ~lo}; }
193
197 constexpr uint128_t& operator&=(const uint128_t& other) noexcept {
198 hi &= other.hi;
199 lo &= other.lo;
200 return *this;
201 }
202
206 constexpr uint128_t& operator|=(const uint128_t& other) noexcept {
207 hi |= other.hi;
208 lo |= other.lo;
209 return *this;
210 }
211
215 constexpr uint128_t& operator^=(const uint128_t& other) noexcept {
216 hi ^= other.hi;
217 lo ^= other.lo;
218 return *this;
219 }
220
225 constexpr uint128_t& operator<<=(const uint32_t shift) noexcept {
226 if (shift == 0) {
227 return *this;
228 }
229 if (shift >= 128) {
230 hi = 0;
231 lo = 0;
232 return *this;
233 }
234 if (shift >= 64) {
235 hi = lo << (shift - 64);
236 lo = 0;
237 return *this;
238 }
239 hi = (hi << shift) | (lo >> (64 - shift));
240 lo = lo << shift;
241 return *this;
242 }
243
248 constexpr uint128_t& operator>>=(const uint32_t shift) noexcept {
249 if (shift == 0) {
250 return *this;
251 }
252 if (shift >= 128) {
253 hi = 0;
254 lo = 0;
255 return *this;
256 }
257 if (shift >= 64) {
258 lo = hi >> (shift - 64);
259 hi = 0;
260 return *this;
261 }
262 lo = (lo >> shift) | (hi << (64 - shift));
263 hi = hi >> shift;
264 return *this;
265 }
266
273 static uint128_t mul64(uint64_t a, uint64_t b) noexcept;
274
281 uint64_t div64(uint64_t divisor, uint64_t* remainder = nullptr) const;
282
286 NEFORCE_NODISCARD constexpr size_t to_hash() const noexcept {
287 constexpr uint64_t GOLDEN = 0x9E3779B97F4A7C15ULL;
288 size_t seed = hash<uint64_t>()(lo);
289 seed ^= hash<uint64_t>()(hi) + GOLDEN + (seed << 6) + (seed >> 2);
290 return seed;
291 }
292
299 static constexpr uint128_t parse(const string_view view) { return uint128_t{view}; }
300
305 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string to_string() const;
306
310 static constexpr uint128_t min() noexcept { return {static_cast<uint64_t>(0), static_cast<uint64_t>(0)}; }
311
315 static constexpr uint128_t max() noexcept { return {~static_cast<uint64_t>(0), ~static_cast<uint64_t>(0)}; }
316};
317
322struct NEFORCE_API int128_t : icommon<int128_t>, iarithmetic<int128_t>, ibinary<int128_t>, iobject<int128_t> {
323public:
326
327 constexpr int128_t() noexcept = default;
328 NEFORCE_CONSTEXPR20 ~int128_t() = default;
329
333 constexpr int128_t(const long value) noexcept :
334 int128_t(static_cast<make_integer_t<sizeof(long)>>(value)) {}
335
339 constexpr int128_t(const int32_t value) noexcept :
340 int128_t(static_cast<long long>(value)) {}
341
345 constexpr int128_t(const long long value) noexcept :
346 lo(static_cast<uint64_t>(value)),
347 hi(value < 0 ? ~static_cast<uint64_t>(0) : 0) {}
348
354 constexpr int128_t(const uint64_t low, const bool negative = false) noexcept :
355 lo(low),
356 hi(negative ? ~static_cast<uint64_t>(0) : 0) {}
357
363 constexpr int128_t(const uint64_t high, const uint64_t low) noexcept :
364 lo(low),
365 hi(high) {}
366
367 constexpr int128_t(const int128_t&) noexcept = default;
368 constexpr int128_t& operator=(const int128_t&) noexcept = default;
369 constexpr int128_t(int128_t&&) noexcept = default;
370 constexpr int128_t& operator=(int128_t&&) noexcept = default;
371
375 constexpr int128_t& operator=(const uint128_t& other) noexcept {
376 lo = other.lo;
377 hi = other.hi;
378 return *this;
379 }
380
387 explicit NEFORCE_CONSTEXPR20 int128_t(const string& str, int base = 10) :
388 int128_t(str.view(), base) {}
389
396 explicit constexpr int128_t(string_view str, int base = 10);
397
401 NEFORCE_NODISCARD constexpr uint128_t to_uint128() const noexcept { return {hi, lo}; }
402
403 explicit constexpr operator bool() const noexcept { return (lo != 0U) || (hi != 0U); }
404 explicit constexpr operator char() const noexcept { return static_cast<char>(lo); }
405 explicit constexpr operator int8_t() const noexcept { return static_cast<int8_t>(lo); }
406 explicit constexpr operator int16_t() const noexcept { return static_cast<int16_t>(lo); }
407 explicit constexpr operator int32_t() const noexcept { return static_cast<int32_t>(lo); }
408 explicit constexpr operator int64_t() const noexcept { return static_cast<int64_t>(lo); }
409 explicit constexpr operator uint8_t() const noexcept { return static_cast<uint8_t>(lo); }
410 explicit constexpr operator uint16_t() const noexcept { return static_cast<uint16_t>(lo); }
411 explicit constexpr operator uint32_t() const noexcept { return static_cast<uint32_t>(lo); }
412 explicit constexpr operator uint64_t() const noexcept { return lo; }
413 explicit constexpr operator uint128_t() const noexcept { return to_uint128(); }
414
418 NEFORCE_NODISCARD constexpr bool is_negative() const noexcept { return static_cast<int64_t>(hi) < 0; }
419
423 NEFORCE_NODISCARD constexpr bool equal_to(const int128_t& rhs) const noexcept {
424 return hi == rhs.hi && lo == rhs.lo;
425 }
426
430 NEFORCE_NODISCARD constexpr bool less_than(const int128_t& rhs) const noexcept {
431 const bool a_neg = is_negative();
432 const bool b_neg = rhs.is_negative();
433 if (a_neg != b_neg) {
434 return a_neg;
435 }
436 return hi < rhs.hi || (hi == rhs.hi && lo < rhs.lo);
437 }
438
442 constexpr int128_t operator-() const noexcept {
443 const uint64_t new_lo = ~lo + 1ULL;
444 const uint64_t new_hi = ~hi + (lo == 0ULL ? 1ULL : 0ULL);
445 return {new_hi, new_lo};
446 }
447
451 int128_t& operator+=(const int128_t& other) noexcept;
452
456 int128_t& operator-=(const int128_t& other) noexcept;
457
461 int128_t& operator*=(const int128_t& other) noexcept;
462
467 int128_t& operator/=(const int128_t& other);
468
473 int128_t& operator%=(const int128_t& other);
474
478 int128_t& operator++() noexcept {
479 *this += 1;
480 return *this;
481 }
482
486 int128_t& operator--() noexcept {
487 *this -= 1;
488 return *this;
489 }
490
494 constexpr int128_t operator~() const noexcept { return {~hi, ~lo}; }
495
499 constexpr int128_t& operator&=(const int128_t& other) noexcept {
500 hi &= other.hi;
501 lo &= other.lo;
502 return *this;
503 }
504
508 constexpr int128_t& operator|=(const int128_t& other) noexcept {
509 hi |= other.hi;
510 lo |= other.lo;
511 return *this;
512 }
513
517 constexpr int128_t& operator^=(const int128_t& other) noexcept {
518 hi ^= other.hi;
519 lo ^= other.lo;
520 return *this;
521 }
522
526 constexpr int128_t& operator<<=(const uint32_t shift) noexcept {
527 *this = to_uint128() << shift;
528 return *this;
529 }
530
534 constexpr int128_t& operator>>=(const uint32_t shift) noexcept {
535 if (shift == 0) {
536 return *this;
537 }
538 const bool neg = is_negative();
539 if (shift >= 128) {
540 *this = neg ? int128_t(~static_cast<uint64_t>(0), ~static_cast<uint64_t>(0)) : int128_t(0);
541 return *this;
542 }
543 if (shift >= 64) {
544 lo = static_cast<uint64_t>(static_cast<int64_t>(hi) >> (shift - 64));
545 hi = neg ? ~0ULL : 0ULL;
546 } else {
547 lo = (lo >> shift) | (hi << (64 - shift));
548 hi = static_cast<uint64_t>(static_cast<int64_t>(hi) >> shift);
549 }
550 return *this;
551 }
552
556 NEFORCE_NODISCARD constexpr size_t to_hash() const noexcept {
557 constexpr uint64_t GOLDEN = 0x9E3779B97F4A7C15ULL;
558 size_t seed = hash<uint64_t>()(lo);
559 seed ^= hash<uint64_t>()(hi) + GOLDEN + (seed << 6) + (seed >> 2);
560 return seed;
561 }
562
569 static constexpr int128_t parse(const string_view view) { return int128_t{view}; }
570
575 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string to_string() const;
576
580 static constexpr int128_t min() noexcept {
581 return {static_cast<uint64_t>(0x8000000000000000ULL), static_cast<uint64_t>(0ULL)};
582 }
583
587 static constexpr int128_t max() noexcept { return {0x7FFFFFFFFFFFFFFFULL, ~static_cast<uint64_t>(0)}; }
588};
589 // Int128
591
592template <>
593struct make_signed<uint128_t> {
594 using type = int128_t;
595};
596
597template <>
598struct make_unsigned<int128_t> {
599 using type = uint128_t;
600};
601
602#define __NEFORCE_DEFINE_MAKE_SIGN(CV) \
603 template <> \
604 struct make_signed<uint128_t CV> { \
605 using type = int128_t; \
606 }; \
607 template <> \
608 struct make_unsigned<int128_t CV> { \
609 using type = uint128_t; \
610 };
611NEFORCE_MACRO_RANGES_CV_REF(__NEFORCE_DEFINE_MAKE_SIGN)
612#undef __NEFORCE_DEFINE_MAKE_SIGN
613
614
615template <>
616struct is_integral<uint128_t> : true_type {};
617
618template <>
619struct is_unsigned<uint128_t> : true_type {};
620
621NEFORCE_CONSTEXPR20 string uint128_t::to_string() const { return inner::__int_to_string_dispatch<uint128_t>(*this); }
622
623constexpr uint128_t operator-(const uint128_t& lhs, const uint128_t& rhs) noexcept {
624 const uint64_t new_lo = lhs.lo - rhs.lo;
625 const uint64_t new_hi = lhs.hi - rhs.hi - static_cast<uint64_t>(lhs.lo < rhs.lo);
626 return {new_hi, new_lo};
627}
628
629
630template <>
631struct is_integral<int128_t> : true_type {};
632
633template <>
634struct is_signed<int128_t> : true_type {};
635
636NEFORCE_CONSTEXPR20 string int128_t::to_string() const { return inner::__int_to_string_dispatch<int128_t>(*this); }
637
638constexpr int128_t operator-(const int128_t& lhs, const int128_t& rhs) noexcept {
639 const uint128_t a = lhs.to_uint128();
640 const uint128_t b = rhs.to_uint128();
641 const uint128_t c = a - b;
642 return {c.hi, c.lo};
643}
644
645constexpr int128_t uint128_t::to_int128() const noexcept { return {hi, lo}; }
646constexpr uint128_t::operator int128_t() const noexcept { return {hi, lo}; }
647
648
649NEFORCE_BEGIN_LITERALS__
650
656
662constexpr uint128_t operator""_u128(const unsigned long long val) noexcept { return {static_cast<uint64_t>(val)}; }
663
669constexpr int128_t operator""_i128(const unsigned long long val) noexcept { return {static_cast<uint64_t>(val)}; }
670
678constexpr uint128_t operator""_u128(const char* str, const size_t len) { return uint128_t(string_view{str, len}); }
679
687constexpr int128_t operator""_i128(const char* str, const size_t len) { return int128_t(string_view{str, len}); }
688 // UserLiterals
690
691NEFORCE_END_LITERALS__
692
697
701template <>
703public:
704 static constexpr bool is_specialized = true;
705 static constexpr bool is_signed = false;
706 static constexpr bool is_integer = true;
707 static constexpr bool is_exact = true;
708 static constexpr bool has_infinity = false;
709 static constexpr bool has_quiet_NaN = false;
710 static constexpr bool has_signaling_NaN = false;
711 static constexpr auto has_denorm = float_denorm_type::ABSENT;
712 static constexpr bool has_denorm_loss = false;
713 static constexpr auto round_style = float_round_type::TOWARD_ZERO;
714 static constexpr bool is_iec559 = false;
715 static constexpr bool is_bounded = true;
716 static constexpr bool is_modulo = true;
717 static constexpr int digits = 128;
718 static constexpr int digits10 = 38;
719 static constexpr int max_digits10 = 0;
720 static constexpr int radix = 2;
721 static constexpr int min_exponent = 0;
722 static constexpr int min_exponent10 = 0;
723 static constexpr int max_exponent = 0;
724 static constexpr int max_exponent10 = 0;
725 static constexpr bool traps = true;
726 static constexpr bool tinyness_before = false;
727 static constexpr uint128_t min() noexcept { return uint128_t::min(); }
728 static constexpr uint128_t lowest() noexcept { return uint128_t::min(); }
729 static constexpr uint128_t max() noexcept { return uint128_t::max(); }
730 static constexpr uint128_t epsilon() noexcept { return 0; }
731 static constexpr uint128_t round_error() noexcept { return 0; }
732 static constexpr uint128_t infinity() noexcept { return 0; }
733 static constexpr uint128_t quiet_NaN() noexcept { return 0; }
734 static constexpr uint128_t signaling_NaN() noexcept { return 0; }
735 static constexpr uint128_t denorm_min() noexcept { return 0; }
736};
737
741template <>
743public:
744 static constexpr bool is_specialized = true;
745 static constexpr bool is_signed = true;
746 static constexpr bool is_integer = true;
747 static constexpr bool is_exact = true;
748 static constexpr bool has_infinity = false;
749 static constexpr bool has_quiet_NaN = false;
750 static constexpr bool has_signaling_NaN = false;
751 static constexpr auto has_denorm = float_denorm_type::ABSENT;
752 static constexpr bool has_denorm_loss = false;
753 static constexpr auto round_style = float_round_type::TOWARD_ZERO;
754 static constexpr bool is_iec559 = false;
755 static constexpr bool is_bounded = true;
756 static constexpr bool is_modulo = false;
757 static constexpr int digits = 127;
758 static constexpr int digits10 = 38;
759 static constexpr int max_digits10 = 0;
760 static constexpr int radix = 2;
761 static constexpr int min_exponent = 0;
762 static constexpr int min_exponent10 = 0;
763 static constexpr int max_exponent = 0;
764 static constexpr int max_exponent10 = 0;
765 static constexpr bool traps = true;
766 static constexpr bool tinyness_before = false;
767 static constexpr int128_t min() noexcept { return int128_t::min(); }
768 static constexpr int128_t lowest() noexcept { return int128_t::min(); }
769 static constexpr int128_t max() noexcept { return int128_t::max(); }
770 static constexpr int128_t epsilon() noexcept { return 0; }
771 static constexpr int128_t round_error() noexcept { return 0; }
772 static constexpr int128_t infinity() noexcept { return 0; }
773 static constexpr int128_t quiet_NaN() noexcept { return 0; }
774 static constexpr int128_t signaling_NaN() noexcept { return 0; }
775 static constexpr int128_t denorm_min() noexcept { return 0; }
776};
777 // NumericTraits
779
784
793NEFORCE_NODISCARD constexpr uint128_t to_uint128(const string_view sv, size_t* idx = nullptr, const int base = 10) {
794 char* endptr = nullptr;
795 const uint128_t num = inner::str_to_uints<uint128_t>(sv, &endptr, base);
796 if (sv.data() == endptr) {
797 NEFORCE_THROW_EXCEPTION(typecast_exception("Convert from string failed."));
798 }
799 if (idx != nullptr) {
800 *idx = static_cast<size_t>(endptr - sv.data());
801 }
802 return num;
803}
804
813NEFORCE_NODISCARD constexpr int128_t to_int128(const string_view sv, size_t* idx = nullptr, const int base = 10) {
814 char* endptr = nullptr;
815 const int128_t num = inner::str_to_ints<int128_t>(sv, &endptr, base);
816 if (sv.data() == endptr) {
817 NEFORCE_THROW_EXCEPTION(typecast_exception("Convert from string failed."));
818 }
819 if (idx != nullptr) {
820 *idx = static_cast<size_t>(endptr - sv.data());
821 }
822 return num;
823}
824 // StringConverts
826
827constexpr uint128_t::uint128_t(const string_view str, const int base) { *this = to_uint128(str, nullptr, base); }
828
829constexpr int128_t::int128_t(const string_view str, const int base) { *this = to_int128(str, nullptr, base); }
830
831NEFORCE_END_NAMESPACE__
832#endif // NEFORCE_CORE_NUMERIC_INT128_HPP__
constexpr const_pointer data() const noexcept
获取底层数据指针
数值类型极限特性主模板
static constexpr T denorm_min() noexcept
获取最小的次正规化正值
static constexpr T lowest() noexcept
获取类型的最低值
static constexpr T round_error() noexcept
获取最大舍入误差
static constexpr T infinity() noexcept
获取正无穷大表示
static constexpr T max() noexcept
获取类型的最大值
static constexpr T epsilon() noexcept
获取机器精度
static constexpr T min() noexcept
获取类型的最小值
unsigned char uint8_t
8位无符号整数类型
unsigned int uint32_t
32位无符号整数类型
long long int64_t
64位有符号整数类型
unsigned short uint16_t
16位无符号整数类型
unsigned long long uint64_t
64位无符号整数类型
short int16_t
16位有符号整数类型
int int32_t
32位有符号整数类型
signed char int8_t
8位有符号整数类型
constexpr decimal_t remainder(const decimal_t x, const decimal_t y) noexcept
计算余数
constexpr auto operator-(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept -> decltype(lhs.base() - rhs.base())
减法运算符
@ ABSENT
不支持次正规化
@ TOWARD_ZERO
向零舍入(截断)
constexpr bool is_negative(const T x) noexcept
检查浮点数是否为负数
typename make_integer< Size, IsSigned >::type make_integer_t
make_integer的便捷别名
constexpr uint128_t to_uint128(const string_view sv, size_t *idx=nullptr, const int base=10)
将字符串转换为128位无符号整数
constexpr int128_t to_int128(const string_view sv, size_t *idx=nullptr, const int base=10)
将字符串转换为128位有符号整数
basic_string_view< char > string_view
字符字符串视图
#define NEFORCE_MACRO_RANGES_CV_REF(MAC)
cv和引用限定符列表宏
bool_constant< true > true_type
表示true的类型
constexpr string to_string(const CharT &c)
将字符转换为普通字符串
数值操作接口
可解析对象接口
哈希函数的主模板
算术运算接口基类
位运算接口基类
通用接口,同时具备可比较和可哈希功能
128位有符号整数类型
uint64_t hi
高64位
int128_t & operator*=(const int128_t &other) noexcept
乘法赋值
int128_t & operator%=(const int128_t &other)
取模赋值
constexpr string to_string() const
转换为字符串
uint64_t lo
低64位
constexpr int128_t & operator|=(const int128_t &other) noexcept
按位或赋值
constexpr uint128_t to_uint128() const noexcept
转换为无符号128位整数
constexpr int128_t(const int32_t value) noexcept
从32位有符号整数构造
constexpr bool is_negative() const noexcept
检查是否为负数
int128_t & operator--() noexcept
前置自减
constexpr int128_t & operator&=(const int128_t &other) noexcept
按位与赋值
int128_t & operator++() noexcept
前置自增
constexpr int128_t & operator^=(const int128_t &other) noexcept
按位异或赋值
constexpr bool equal_to(const int128_t &rhs) const noexcept
相等比较
constexpr int128_t(const uint64_t low, const bool negative=false) noexcept
从低64位和符号构造
constexpr int128_t operator-() const noexcept
负号
int128_t & operator-=(const int128_t &other) noexcept
减法赋值
constexpr size_t to_hash() const noexcept
计算哈希值
int128_t & operator+=(const int128_t &other) noexcept
加法赋值
constexpr int128_t(const string &str, int base=10)
从字符串构造
constexpr bool less_than(const int128_t &rhs) const noexcept
小于比较(考虑符号)
int128_t & operator/=(const int128_t &other)
除法赋值
static constexpr int128_t parse(const string_view view)
从字符串解析
constexpr int128_t & operator<<=(const uint32_t shift) noexcept
左移赋值
static constexpr int128_t min() noexcept
获取最小值
constexpr int128_t(const uint64_t high, const uint64_t low) noexcept
从高低64位构造
constexpr int128_t(const long long value) noexcept
从 long long 构造
static constexpr int128_t max() noexcept
获取最大值
constexpr int128_t operator~() const noexcept
按位取反
constexpr int128_t & operator>>=(const uint32_t shift) noexcept
右移赋值(算术右移)
可解析对象接口
判断类型是否为整数类型
判断类型是否为有符号类型
判断类型是否为无符号类型
将类整数类型转换为对应的有符号类型
将类整数类型转换为对应的无符号类型
类型转换异常
128位无符号整数类型
static constexpr uint128_t max() noexcept
获取最大值
constexpr uint128_t operator-() const noexcept
取负
uint128_t & operator/=(const uint128_t &other)
除法赋值
uint128_t & operator--() noexcept
前置自减
uint128_t & operator++() noexcept
前置自增
constexpr uint128_t(const unsigned long low) noexcept
从无符号 long 构造
uint128_t & operator*=(const uint128_t &other) noexcept
乘法赋值
uint64_t hi
高64位
constexpr bool equal_to(const uint128_t &rhs) const noexcept
相等比较
constexpr uint128_t(const unsigned long long low) noexcept
从无符号 long long 构造
constexpr uint128_t & operator|=(const uint128_t &other) noexcept
按位或赋值
constexpr int128_t to_int128() const noexcept
转换为有符号128位整数
constexpr uint128_t & operator^=(const uint128_t &other) noexcept
按位异或赋值
constexpr uint128_t & operator&=(const uint128_t &other) noexcept
按位与赋值
uint128_t & operator-=(const uint128_t &other) noexcept
减法赋值
uint128_t & operator+=(const uint128_t &other) noexcept
加法赋值
uint64_t div64(uint64_t divisor, uint64_t *remainder=nullptr) const
64位除法
constexpr size_t to_hash() const noexcept
计算哈希值
uint128_t & operator%=(const uint128_t &other)
取模赋值
constexpr string to_string() const
转换为字符串
uint64_t lo
低64位
constexpr uint128_t operator~() const noexcept
按位取反
static uint128_t mul64(uint64_t a, uint64_t b) noexcept
64位乘法
constexpr uint128_t & operator<<=(const uint32_t shift) noexcept
左移赋值
constexpr bool less_than(const uint128_t &rhs) const noexcept
小于比较
static constexpr uint128_t parse(const string_view view)
从字符串解析
constexpr uint128_t & operator>>=(const uint32_t shift) noexcept
右移赋值
constexpr uint128_t(const uint32_t low) noexcept
从32位无符号整数构造
constexpr uint128_t(const uint64_t high, const uint64_t low) noexcept
从高低64位构造
static constexpr uint128_t min() noexcept
获取最小值
字符串到数值的转换函数
类型到字符串的转换函数