[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 06e5af60 2/2: Fix defect introduced 20220527T
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 06e5af60 2/2: Fix defect introduced 20220527T2230Z: negated integer minimum |
Date: |
Fri, 3 Jun 2022 17:14:18 -0400 (EDT) |
branch: master
commit 06e5af6027b2b7fc87bb139827ec0b893e3f2cac
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Fix defect introduced 20220527T2230Z: negated integer minimum
Commit bff73872e59f44 of 20220527T2230Z changed a lower bound from
-max() to -lowest(): the negative of an integer minimum.
Although the test is used only for floating-point types, this lowest()
is an integer limit:
constexpr auto z1lo = std::numeric_limits<long long int>::lowest();
But an integer lowest() is the negative of an integral power of two,
and negating it reliably preserves its value in two's-complement
arithmetic (thus, for int8_t, negating -128 yields -128), though in
C and C++ it's UB. Naturally gcc returns -2^63, whose negative is
itself, so no failing unit test can be devised.
---
tn_range.tpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tn_range.tpp b/tn_range.tpp
index 8495223d..fd74be98 100644
--- a/tn_range.tpp
+++ b/tn_range.tpp
@@ -204,7 +204,7 @@ namespace
return
-z0 < t
&& t < z0
- && -z1lo < t
+ && z1lo < t
&& t < z1hi
&& t == static_cast<long long int>(t)
;