Implement 128-bit operator+= for uint128_fallback

This commit is contained in:
Victor Zverovich
2022-03-27 08:07:45 -07:00
parent b41890c1e5
commit 96930161f9
2 changed files with 18 additions and 6 deletions

View File

@@ -363,9 +363,12 @@ class uint128_fallback {
FMT_CONSTEXPR auto operator>>=(int shift) -> uint128_fallback& {
return *this = *this >> shift;
}
FMT_CONSTEXPR void operator+=(uint64_t n) {
lo_ += n;
if (lo_ < n) ++hi_;
FMT_CONSTEXPR void operator+=(uint128_fallback n) {
uint64_t new_lo = lo_ + n.lo_;
uint64_t new_hi = hi_ + n.hi_ + (new_lo < lo_ ? 1 : 0);
FMT_ASSERT(new_hi >= hi_, "");
lo_ = new_lo;
hi_ = new_hi;
}
};