about summary refs log tree commit diff
path: root/absl/numeric/int128.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-01-10T19·46-0800
committerDerek Mauro <dmauro@google.com>2018-01-10T20·36-0500
commitc742b72354a84958b6a061755249822eeef87d06 (patch)
treebf7c3480e1b7396124625c49ccc103bb7bdc6008 /absl/numeric/int128.h
parent98bff8b2bc53aa271c0dd0dff1b33730b4df8481 (diff)
Changes imported from Abseil "staging" branch:
  - f679f7de2957ac4dca0a862d04f1165d2f503525 Merge GitHub PR #78: Fix typo in thread_identity.h by Derek Mauro <dmauro@google.com>
  - 369cbefc9ebb8503e3c25b1516c856dab3bed7ac Minor refactor of operator-(uint128). by Alex Strelnikov <strel@google.com>
  - fba0f8c33b051d90936ad0fcaa4bea83f554bf8d Merge GitHub PR #75: Fix typo in per_thread_tls.h by Derek Mauro <dmauro@google.com>
  - 76d5d25a54ab93c1ea3bc74b5a28ba335b0f2bab Implement InlinedVector::shrink_to_fit() method. by Abseil Team <absl-team@google.com>

GitOrigin-RevId: f679f7de2957ac4dca0a862d04f1165d2f503525
Change-Id: I03b39fdbd70c00a455d98d949d413dd7c8019578
Diffstat (limited to 'absl/numeric/int128.h')
-rw-r--r--absl/numeric/int128.h11
1 files changed, 4 insertions, 7 deletions
diff --git a/absl/numeric/int128.h b/absl/numeric/int128.h
index f42a4aa3788e..a204ac4d9c3f 100644
--- a/absl/numeric/int128.h
+++ b/absl/numeric/int128.h
@@ -460,13 +460,10 @@ inline bool operator>=(uint128 lhs, uint128 rhs) {
 // Unary operators.
 
 inline uint128 operator-(uint128 val) {
-  const uint64_t hi_flip = ~Uint128High64(val);
-  const uint64_t lo_flip = ~Uint128Low64(val);
-  const uint64_t lo_add = lo_flip + 1;
-  if (lo_add < lo_flip) {
-    return MakeUint128(hi_flip + 1, lo_add);
-  }
-  return MakeUint128(hi_flip, lo_add);
+  uint64_t hi = ~Uint128High64(val);
+  uint64_t lo = ~Uint128Low64(val) + 1;
+  if (lo == 0) ++hi;  // carry
+  return MakeUint128(hi, lo);
 }
 
 inline bool operator!(uint128 val) {