Go to the documentation of this file.
26 #ifndef ABSL_NUMERIC_INT128_H_
27 #define ABSL_NUMERIC_INT128_H_
37 #include "absl/base/config.h"
38 #include "absl/base/macros.h"
39 #include "absl/base/port.h"
46 #define ABSL_INTERNAL_WCHAR_T __wchar_t
47 #if defined(_M_X64) && !defined(_M_ARM64EC)
49 #pragma intrinsic(_umul128)
50 #endif // defined(_M_X64)
51 #else // defined(_MSC_VER)
52 #define ABSL_INTERNAL_WCHAR_T wchar_t
53 #endif // defined(_MSC_VER)
105 #if defined(ABSL_HAVE_INTRINSIC_INT128)
106 alignas(
unsigned __int128)
118 constexpr
uint128(
unsigned long long v);
119 #ifdef ABSL_HAVE_INTRINSIC_INT128
121 constexpr
uint128(
unsigned __int128
v);
122 #endif // ABSL_HAVE_INTRINSIC_INT128
132 uint128& operator=(
unsigned long v);
134 uint128& operator=(
unsigned long long v);
135 #ifdef ABSL_HAVE_INTRINSIC_INT128
137 uint128& operator=(
unsigned __int128
v);
138 #endif // ABSL_HAVE_INTRINSIC_INT128
142 constexpr
explicit operator bool()
const;
143 constexpr
explicit operator char()
const;
144 constexpr
explicit operator signed char()
const;
145 constexpr
explicit operator unsigned char()
const;
146 constexpr
explicit operator char16_t()
const;
147 constexpr
explicit operator char32_t()
const;
149 constexpr
explicit operator short()
const;
151 constexpr
explicit operator unsigned short()
const;
152 constexpr
explicit operator int()
const;
153 constexpr
explicit operator unsigned int()
const;
154 constexpr
explicit operator long()
const;
156 constexpr
explicit operator unsigned long()
const;
158 constexpr
explicit operator long long()
const;
160 constexpr
explicit operator unsigned long long()
const;
161 #ifdef ABSL_HAVE_INTRINSIC_INT128
162 constexpr
explicit operator __int128()
const;
163 constexpr
explicit operator unsigned __int128()
const;
164 #endif // ABSL_HAVE_INTRINSIC_INT128
165 explicit operator float()
const;
166 explicit operator double()
const;
167 explicit operator long double()
const;
215 template <
typename H>
227 #if defined(ABSL_IS_LITTLE_ENDIAN)
230 #elif defined(ABSL_IS_BIG_ENDIAN)
234 #error "Unsupported byte order: must be little-endian or big-endian."
244 std::ostream&
operator<<(std::ostream& os, uint128
v);
259 class numeric_limits<
absl::uint128> {
261 static constexpr
bool is_specialized =
true;
262 static constexpr
bool is_signed =
false;
263 static constexpr
bool is_integer =
true;
264 static constexpr
bool is_exact =
true;
265 static constexpr
bool has_infinity =
false;
266 static constexpr
bool has_quiet_NaN =
false;
267 static constexpr
bool has_signaling_NaN =
false;
268 static constexpr float_denorm_style has_denorm = denorm_absent;
269 static constexpr
bool has_denorm_loss =
false;
270 static constexpr float_round_style round_style = round_toward_zero;
271 static constexpr
bool is_iec559 =
false;
272 static constexpr
bool is_bounded =
true;
273 static constexpr
bool is_modulo =
true;
274 static constexpr
int digits = 128;
275 static constexpr
int digits10 = 38;
276 static constexpr
int max_digits10 = 0;
279 static constexpr
int min_exponent10 = 0;
280 static constexpr
int max_exponent = 0;
281 static constexpr
int max_exponent10 = 0;
282 #ifdef ABSL_HAVE_INTRINSIC_INT128
283 static constexpr
bool traps = numeric_limits<unsigned __int128>::traps;
284 #else // ABSL_HAVE_INTRINSIC_INT128
285 static constexpr
bool traps = numeric_limits<uint64_t>::traps;
286 #endif // ABSL_HAVE_INTRINSIC_INT128
287 static constexpr
bool tinyness_before =
false;
344 constexpr
int128(
unsigned int v);
346 constexpr
int128(
unsigned long v);
348 constexpr
int128(
unsigned long long v);
349 #ifdef ABSL_HAVE_INTRINSIC_INT128
351 constexpr
explicit int128(
unsigned __int128
v);
352 #endif // ABSL_HAVE_INTRINSIC_INT128
356 explicit int128(
long double v);
365 #ifdef ABSL_HAVE_INTRINSIC_INT128
367 #endif // ABSL_HAVE_INTRINSIC_INT128
370 constexpr
explicit operator bool()
const;
371 constexpr
explicit operator char()
const;
372 constexpr
explicit operator signed char()
const;
373 constexpr
explicit operator unsigned char()
const;
374 constexpr
explicit operator char16_t()
const;
375 constexpr
explicit operator char32_t()
const;
377 constexpr
explicit operator short()
const;
379 constexpr
explicit operator unsigned short()
const;
380 constexpr
explicit operator int()
const;
381 constexpr
explicit operator unsigned int()
const;
382 constexpr
explicit operator long()
const;
384 constexpr
explicit operator unsigned long()
const;
386 constexpr
explicit operator long long()
const;
388 constexpr
explicit operator unsigned long long()
const;
389 #ifdef ABSL_HAVE_INTRINSIC_INT128
390 constexpr
explicit operator __int128()
const;
391 constexpr
explicit operator unsigned __int128()
const;
392 #endif // ABSL_HAVE_INTRINSIC_INT128
393 explicit operator float()
const;
394 explicit operator double()
const;
395 explicit operator long double()
const;
452 template <
typename H>
460 #if defined(ABSL_HAVE_INTRINSIC_INT128)
462 #else // ABSL_HAVE_INTRINSIC_INT128
463 #if defined(ABSL_IS_LITTLE_ENDIAN)
466 #elif defined(ABSL_IS_BIG_ENDIAN)
470 #error "Unsupported byte order: must be little-endian or big-endian."
472 #endif // ABSL_HAVE_INTRINSIC_INT128
475 std::ostream&
operator<<(std::ostream& os, int128
v);
494 class numeric_limits<
absl::int128> {
496 static constexpr
bool is_specialized =
true;
497 static constexpr
bool is_signed =
true;
498 static constexpr
bool is_integer =
true;
499 static constexpr
bool is_exact =
true;
500 static constexpr
bool has_infinity =
false;
501 static constexpr
bool has_quiet_NaN =
false;
502 static constexpr
bool has_signaling_NaN =
false;
503 static constexpr float_denorm_style has_denorm = denorm_absent;
504 static constexpr
bool has_denorm_loss =
false;
505 static constexpr float_round_style round_style = round_toward_zero;
506 static constexpr
bool is_iec559 =
false;
507 static constexpr
bool is_bounded =
true;
508 static constexpr
bool is_modulo =
false;
509 static constexpr
int digits = 127;
510 static constexpr
int digits10 = 38;
511 static constexpr
int max_digits10 = 0;
514 static constexpr
int min_exponent10 = 0;
515 static constexpr
int max_exponent = 0;
516 static constexpr
int max_exponent10 = 0;
517 #ifdef ABSL_HAVE_INTRINSIC_INT128
518 static constexpr
bool traps = numeric_limits<__int128>::traps;
519 #else // ABSL_HAVE_INTRINSIC_INT128
520 static constexpr
bool traps = numeric_limits<uint64_t>::traps;
521 #endif // ABSL_HAVE_INTRINSIC_INT128
522 static constexpr
bool tinyness_before =
false;
573 #ifdef ABSL_HAVE_INTRINSIC_INT128
581 #endif // ABSL_HAVE_INTRINSIC_INT128
598 *
this = *
this << amount;
603 *
this = *
this >> amount;
608 *
this = *
this + other;
613 *
this = *
this - other;
618 *
this = *
this * other;
623 *
this = *
this / other;
628 *
this = *
this % other;
638 #if defined(ABSL_IS_LITTLE_ENDIAN)
641 : lo_{low}, hi_{high} {}
643 constexpr uint128::uint128(
int v)
646 constexpr uint128::uint128(
long v)
649 constexpr uint128::uint128(
long long v)
653 constexpr uint128::uint128(
unsigned int v) : lo_{
v}, hi_{0} {}
655 constexpr uint128::uint128(
unsigned long v) : lo_{
v}, hi_{0} {}
657 constexpr uint128::uint128(
unsigned long long v) : lo_{
v}, hi_{0} {}
659 #ifdef ABSL_HAVE_INTRINSIC_INT128
660 constexpr uint128::uint128(__int128
v)
662 hi_{
static_cast<uint64_t>(
static_cast<unsigned __int128
>(
v) >> 64)} {}
663 constexpr uint128::uint128(
unsigned __int128
v)
666 #endif // ABSL_HAVE_INTRINSIC_INT128
668 constexpr uint128::uint128(int128
v)
669 : lo_{Int128Low64(
v)}, hi_{
static_cast<uint64_t>(Int128High64(
v))} {}
671 #elif defined(ABSL_IS_BIG_ENDIAN)
674 : hi_{high}, lo_{low} {}
676 constexpr uint128::uint128(
int v)
688 constexpr uint128::uint128(
unsigned long v) : hi_{0}, lo_{
v} {}
690 constexpr uint128::uint128(
unsigned long long v) : hi_{0}, lo_{
v} {}
692 #ifdef ABSL_HAVE_INTRINSIC_INT128
693 constexpr uint128::uint128(__int128
v)
694 : hi_{
static_cast<uint64_t>(
static_cast<unsigned __int128
>(
v) >> 64)},
696 constexpr uint128::uint128(
unsigned __int128
v)
699 #endif // ABSL_HAVE_INTRINSIC_INT128
701 constexpr uint128::uint128(int128
v)
702 : hi_{
static_cast<uint64_t>(Int128High64(
v))}, lo_{Int128Low64(
v)} {}
705 #error "Unsupported byte order: must be little-endian or big-endian."
710 constexpr uint128::operator
bool()
const {
return lo_ || hi_; }
712 constexpr uint128::operator char()
const {
return static_cast<char>(lo_); }
714 constexpr uint128::operator
signed char()
const {
715 return static_cast<signed char>(lo_);
718 constexpr uint128::operator
unsigned char()
const {
719 return static_cast<unsigned char>(lo_);
722 constexpr uint128::operator char16_t()
const {
723 return static_cast<char16_t
>(lo_);
726 constexpr uint128::operator char32_t()
const {
727 return static_cast<char32_t
>(lo_);
735 constexpr uint128::operator short()
const {
return static_cast<short>(lo_); }
737 constexpr uint128::operator
unsigned short()
const {
738 return static_cast<unsigned short>(lo_);
741 constexpr uint128::operator
int()
const {
return static_cast<int>(lo_); }
743 constexpr uint128::operator
unsigned int()
const {
744 return static_cast<unsigned int>(lo_);
748 constexpr uint128::operator
long()
const {
return static_cast<long>(lo_); }
750 constexpr uint128::operator
unsigned long()
const {
751 return static_cast<unsigned long>(lo_);
754 constexpr uint128::operator
long long()
const {
755 return static_cast<long long>(lo_);
758 constexpr uint128::operator
unsigned long long()
const {
759 return static_cast<unsigned long long>(lo_);
762 #ifdef ABSL_HAVE_INTRINSIC_INT128
763 constexpr uint128::operator __int128()
const {
764 return (
static_cast<__int128
>(hi_) << 64) + lo_;
767 constexpr uint128::operator
unsigned __int128()
const {
768 return (
static_cast<unsigned __int128
>(hi_) << 64) + lo_;
770 #endif // ABSL_HAVE_INTRINSIC_INT128
774 inline uint128::operator float()
const {
775 return static_cast<float>(lo_) + std::ldexp(
static_cast<float>(hi_), 64);
778 inline uint128::operator double()
const {
779 return static_cast<double>(lo_) + std::ldexp(
static_cast<double>(hi_), 64);
782 inline uint128::operator
long double()
const {
783 return static_cast<long double>(lo_) +
784 std::ldexp(
static_cast<long double>(hi_), 64);
790 #if defined(ABSL_HAVE_INTRINSIC_INT128)
791 return static_cast<unsigned __int128
>(lhs) ==
792 static_cast<unsigned __int128
>(rhs);
802 #ifdef ABSL_HAVE_INTRINSIC_INT128
803 return static_cast<unsigned __int128
>(lhs) <
804 static_cast<unsigned __int128
>(rhs);
829 #if defined(ABSL_HAVE_INTRINSIC_INT128)
830 return -
static_cast<unsigned __int128
>(val);
839 #if defined(ABSL_HAVE_INTRINSIC_INT128)
840 return !
static_cast<unsigned __int128
>(val);
849 #if defined(ABSL_HAVE_INTRINSIC_INT128)
850 return ~static_cast<unsigned __int128>(val);
857 #if defined(ABSL_HAVE_INTRINSIC_INT128)
858 return static_cast<unsigned __int128
>(lhs) |
859 static_cast<unsigned __int128
>(rhs);
867 #if defined(ABSL_HAVE_INTRINSIC_INT128)
868 return static_cast<unsigned __int128
>(lhs) &
869 static_cast<unsigned __int128
>(rhs);
877 #if defined(ABSL_HAVE_INTRINSIC_INT128)
878 return static_cast<unsigned __int128
>(lhs) ^
879 static_cast<unsigned __int128
>(rhs);
887 *
this = *
this | other;
892 *
this = *
this & other;
897 *
this = *
this ^ other;
904 #ifdef ABSL_HAVE_INTRINSIC_INT128
905 return static_cast<unsigned __int128
>(lhs) << amount;
918 #ifdef ABSL_HAVE_INTRINSIC_INT128
919 return static_cast<unsigned __int128
>(lhs) >> amount;
931 #if !defined(ABSL_HAVE_INTRINSIC_INT128)
932 namespace int128_internal {
943 #if defined(ABSL_HAVE_INTRINSIC_INT128)
944 return static_cast<unsigned __int128
>(lhs) +
945 static_cast<unsigned __int128
>(rhs);
954 #if !defined(ABSL_HAVE_INTRINSIC_INT128)
955 namespace int128_internal {
966 #if defined(ABSL_HAVE_INTRINSIC_INT128)
967 return static_cast<unsigned __int128
>(lhs) -
968 static_cast<unsigned __int128
>(rhs);
978 #if defined(ABSL_HAVE_INTRINSIC_INT128)
981 return static_cast<unsigned __int128
>(lhs) *
982 static_cast<unsigned __int128
>(rhs);
983 #elif defined(_MSC_VER) && defined(_M_X64) && !defined(_M_ARM64EC)
989 #else // ABSL_HAVE_INTRINSIC128
1001 #endif // ABSL_HAVE_INTRINSIC128
1004 #if defined(ABSL_HAVE_INTRINSIC_INT128)
1005 inline uint128
operator/(uint128 lhs, uint128 rhs) {
1006 return static_cast<unsigned __int128
>(lhs) /
1007 static_cast<unsigned __int128
>(rhs);
1010 inline uint128
operator%(uint128 lhs, uint128 rhs) {
1011 return static_cast<unsigned __int128
>(lhs) %
1012 static_cast<unsigned __int128
>(rhs);
1041 return int128(high, low);
1049 inline int128& int128::operator=(
unsigned int v) {
1058 inline int128& int128::operator=(
unsigned long v) {
1068 inline int128& int128::operator=(
unsigned long long v) {
1086 *
this = *
this + other;
1091 *
this = *
this - other;
1096 *
this = *
this * other;
1101 *
this = *
this / other;
1106 *
this = *
this % other;
1111 *
this = *
this | other;
1116 *
this = *
this & other;
1121 *
this = *
this ^ other;
1125 inline int128& int128::operator<<=(
int amount) {
1126 *
this = *
this << amount;
1130 inline int128& int128::operator>>=(
int amount) {
1131 *
this = *
this >> amount;
1138 namespace int128_internal {
1154 #if defined(ABSL_HAVE_INTRINSIC_INT128)
1155 #include "absl/numeric/int128_have_intrinsic.inc"
1156 #else // ABSL_HAVE_INTRINSIC_INT128
1157 #include "absl/numeric/int128_no_intrinsic.inc"
1158 #endif // ABSL_HAVE_INTRINSIC_INT128
1163 #undef ABSL_INTERNAL_WCHAR_T
1165 #endif // ABSL_NUMERIC_INT128_H_
constexpr int128 Int128Min()
constexpr int128 Int128Max()
constexpr friend int128 Int128Max()
constexpr uint128 operator~(uint128 val)
constexpr int128 operator-(int128 lhs, int128 rhs)
ABSL_NAMESPACE_BEGIN const ABSL_DLL uint128 kuint128max
static constexpr absl::uint128 quiet_NaN()
constexpr int128 operator^(int128 lhs, int128 rhs)
StatusToStringMode & operator^=(StatusToStringMode &lhs, StatusToStringMode rhs)
uint128 & operator+=(uint128 other)
Duration & operator%=(Duration &d1, const Duration &d2)
ABSL_NAMESPACE_BEGIN std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
constexpr uint128 operator-(uint128 lhs, uint128 rhs)
constexpr uint128 Uint128Max()
Duration & operator+=(Duration &d1, const Duration &d2)
static constexpr absl::uint128 denorm_min()
uint128 & operator*=(uint128 other)
int128 & operator*=(int128 other)
constexpr int64_t BitCastToSigned(uint64_t v)
constexpr bool operator>(uint128 lhs, uint128 rhs)
#define ABSL_NAMESPACE_END
#define ABSL_INTERNAL_WCHAR_T
uint128 & operator>>=(int)
uint128 operator%(uint128 lhs, uint128 rhs)
constexpr bool operator<(uint128 lhs, uint128 rhs)
uint128 operator*(uint128 lhs, uint128 rhs)
constexpr friend uint64_t Int128Low64(int128 v)
constexpr uint64_t Uint128High64(uint128 v)
#define ABSL_NAMESPACE_BEGIN
static constexpr absl::int128 lowest()
static constexpr absl::uint128 round_error()
constexpr uint64_t Uint128Low64(uint128 v)
constexpr ABSL_NAMESPACE_BEGIN uint128 MakeUint128(uint64_t high, uint64_t low)
int128 & operator/=(int128 other)
constexpr friend int64_t Int128High64(int128 v)
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
static constexpr absl::int128 signaling_NaN()
int128 & operator&=(int128 other)
constexpr bool operator!(uint128 val)
int128 & operator^=(int128 other)
static constexpr absl::int128 infinity()
unsigned __int64 uint64_t
friend H AbslHashValue(H h, int128 v)
bool operator!=(const Bytes &a, const Bytes &b)
int128 & operator+=(int128 other)
constexpr bool operator<=(uint128 lhs, uint128 rhs)
int128 & operator>>=(int amount)
StatusToStringMode & operator&=(StatusToStringMode &lhs, StatusToStringMode rhs)
int128 & operator<<=(int amount)
static constexpr absl::int128 round_error()
constexpr bool operator>=(uint128 lhs, uint128 rhs)
static void operator++(Engine &e, int unused)
constexpr int128 operator|(int128 lhs, int128 rhs)
Duration & operator/=(Duration &d, int64 r)
constexpr uint128 operator>>(uint128 lhs, int amount)
static constexpr absl::uint128 lowest()
constexpr uint128 operator+(uint128 lhs, uint128 rhs)
constexpr int128 operator&(int128 lhs, int128 rhs)
static constexpr absl::int128 denorm_min()
static constexpr absl::uint128 infinity()
constexpr friend int128 Int128Min()
friend H AbslHashValue(H h, uint128 v)
constexpr int128 operator>>(int128 lhs, int amount)
uint128 & operator%=(uint128 other)
static constexpr absl::uint128 signaling_NaN()
int128 & operator%=(int128 other)
constexpr int128 operator+(int128 lhs, int128 rhs)
int128 & operator-=(int128 other)
uint128 operator/(uint128 lhs, uint128 rhs)
constexpr bool operator==(uint128 lhs, uint128 rhs)
constexpr friend int128 MakeInt128(int64_t high, uint64_t low)
uint128 & operator=(int v)
int128 & operator=(int v)
static constexpr absl::int128 quiet_NaN()
constexpr uint128 AddResult(uint128 result, uint128 lhs)
uint128 & operator<<=(int)
static constexpr absl::uint128 epsilon()
int128 operator*(int128 lhs, int128 rhs)
Duration & operator*=(Duration &d, int64 r)
static constexpr absl::int128 epsilon()
uint128 & operator-=(uint128 other)
constexpr int128 operator<<(int128 lhs, int amount)
StatusToStringMode & operator|=(StatusToStringMode &lhs, StatusToStringMode rhs)
constexpr uint128 SubstructResult(uint128 result, uint128 lhs, uint128 rhs)
uint128 & operator/=(uint128 other)
constexpr int128 MakeInt128(int64_t high, uint64_t low)
Duration & operator-=(Duration &d1, const Duration &d2)
int128 & operator|=(int128 other)
Duration operator/(Duration lhs, int64_t rhs)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:06