1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
From eb4e99cfba02ca6a12048a41535018b4eaa91c7d Mon Sep 17 00:00:00 2001
From: Vcode2407 <vkslog69@gmail.com>
Date: Tue, 16 Jun 2026 23:08:57 +0530
Subject: [PATCH] Fix fallback uint128 bitwise not
---
include/fmt/format.h | 3 +++
test/format-test.cc | 5 +++++
2 files changed, 8 insertions(+)
diff --git a/include/fmt/format.h b/include/fmt/format.h
index 5044befdd863..570627922c62 100644
--- a/include/fmt/format.h
+++ b/include/fmt/format.h
@@ -326,6 +326,9 @@ class uint128 {
-> uint128 {
return {lhs.hi_ & rhs.hi_, lhs.lo_ & rhs.lo_};
}
+ friend constexpr auto operator~(const uint128& n) -> uint128 {
+ return {~n.hi_, ~n.lo_};
+ }
friend FMT_CONSTEXPR auto operator+(const uint128& lhs, const uint128& rhs)
-> uint128 {
auto result = uint128(lhs);
diff --git a/test/format-test.cc b/test/format-test.cc
index 61a53c72f3e6..7e48b751cb67 100644
--- a/test/format-test.cc
+++ b/test/format-test.cc
@@ -81,6 +81,11 @@ TEST(uint128_test, minus) {
EXPECT_EQ(n - 2, 40);
}
+TEST(uint128_test, bitwise_not) {
+ auto n = ~uint128(0x123456789abcdef0, 0x0fedcba987654321);
+ EXPECT_EQ(n, uint128(0xedcba9876543210f, 0xf0123456789abcde));
+}
+
TEST(uint128_test, plus_assign) {
auto n = uint128(32);
n += uint128(10);
|