aboutsummaryrefslogtreecommitdiff
path: root/absl/numeric/int128_no_intrinsic.inc
diff options
context:
space:
mode:
authorBenjamin Barenblat <bbaren@google.com>2024-04-18 10:36:51 -0700
committerCopybara-Service <copybara-worker@google.com>2024-04-18 10:37:56 -0700
commit192e959b16809f751d565b53a949b21129d904fb (patch)
tree6305393afc947dc466f88cdd886bd9139b3f8b21 /absl/numeric/int128_no_intrinsic.inc
parent9a61b00dde4031f17ed4fa4bdc0e0e9ad8859846 (diff)
downloadabseil-192e959b16809f751d565b53a949b21129d904fb.tar.gz
abseil-192e959b16809f751d565b53a949b21129d904fb.tar.bz2
abseil-192e959b16809f751d565b53a949b21129d904fb.zip
Add `operator<=>` support to `absl::int128` and `absl::uint128`
PiperOrigin-RevId: 626080616 Change-Id: If434be2371c1e28f9fd0133f411596bdc38bd222
Diffstat (limited to 'absl/numeric/int128_no_intrinsic.inc')
-rw-r--r--absl/numeric/int128_no_intrinsic.inc18
1 files changed, 18 insertions, 0 deletions
diff --git a/absl/numeric/int128_no_intrinsic.inc b/absl/numeric/int128_no_intrinsic.inc
index 6f5d8377..195b7452 100644
--- a/absl/numeric/int128_no_intrinsic.inc
+++ b/absl/numeric/int128_no_intrinsic.inc
@@ -186,6 +186,24 @@ constexpr bool operator<=(int128 lhs, int128 rhs) { return !(lhs > rhs); }
constexpr bool operator>=(int128 lhs, int128 rhs) { return !(lhs < rhs); }
+#ifdef __cpp_impl_three_way_comparison
+constexpr absl::strong_ordering operator<=>(int128 lhs, int128 rhs) {
+ if (int64_t lhs_high = Int128High64(lhs), rhs_high = Int128High64(rhs);
+ lhs_high < rhs_high) {
+ return absl::strong_ordering::less;
+ } else if (lhs_high > rhs_high) {
+ return absl::strong_ordering::greater;
+ } else if (uint64_t lhs_low = Uint128Low64(lhs), rhs_low = Uint128Low64(rhs);
+ lhs_low < rhs_low) {
+ return absl::strong_ordering::less;
+ } else if (lhs_low > rhs_low) {
+ return absl::strong_ordering::greater;
+ } else {
+ return absl::strong_ordering::equal;
+ }
+}
+#endif
+
// Unary operators.
constexpr int128 operator-(int128 v) {