mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-26 12:35:32 +00:00
Implement 128-bit operator+= for uint128_fallback
This commit is contained in:
parent
b41890c1e5
commit
96930161f9
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -33,6 +33,7 @@ using fmt::memory_buffer;
|
||||
using fmt::runtime;
|
||||
using fmt::string_view;
|
||||
using fmt::detail::max_value;
|
||||
using fmt::detail::uint128_fallback;
|
||||
|
||||
using testing::Return;
|
||||
using testing::StrictMock;
|
||||
@ -40,7 +41,6 @@ using testing::StrictMock;
|
||||
enum { buffer_size = 256 };
|
||||
|
||||
TEST(uint128_test, ctor) {
|
||||
using fmt::detail::uint128_fallback;
|
||||
auto n = uint128_fallback();
|
||||
EXPECT_EQ(n, 0);
|
||||
n = uint128_fallback(42);
|
||||
@ -49,7 +49,7 @@ TEST(uint128_test, ctor) {
|
||||
}
|
||||
|
||||
TEST(uint128_test, shift) {
|
||||
auto n = fmt::detail::uint128_fallback(42);
|
||||
auto n = uint128_fallback(42);
|
||||
n = n << 64;
|
||||
EXPECT_EQ(static_cast<uint64_t>(n), 0);
|
||||
n = n >> 64;
|
||||
@ -62,10 +62,19 @@ TEST(uint128_test, shift) {
|
||||
}
|
||||
|
||||
TEST(uint128_test, minus) {
|
||||
auto n = fmt::detail::uint128_fallback(42);
|
||||
auto n = uint128_fallback(42);
|
||||
EXPECT_EQ(n - 2, 40);
|
||||
}
|
||||
|
||||
TEST(uint128_test, plus_assign) {
|
||||
auto n = uint128_fallback(32);
|
||||
n += uint128_fallback(10);
|
||||
EXPECT_EQ(n, 42);
|
||||
n = uint128_fallback(max_value<uint64_t>());
|
||||
n += uint128_fallback(1);
|
||||
EXPECT_EQ(n, uint128_fallback(1) << 64);
|
||||
}
|
||||
|
||||
template <typename Float> void check_isfinite() {
|
||||
using fmt::detail::isfinite;
|
||||
EXPECT_TRUE(isfinite(Float(0.0)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user