[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master bff73872 3/3: Specify limits more carefully
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master bff73872 3/3: Specify limits more carefully |
Date: |
Fri, 27 May 2022 20:49:11 -0400 (EDT) |
branch: master
commit bff73872e59f44aebcf9ec394d25787283105f08
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Specify limits more carefully
The lowest value for a signed integer type is likely to differ from the
negative of the highest, and more than likely after:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1236r1.html
---
tn_range.tpp | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/tn_range.tpp b/tn_range.tpp
index 563cb037..9d3955af 100644
--- a/tn_range.tpp
+++ b/tn_range.tpp
@@ -171,6 +171,7 @@ namespace
struct is_exact_integer_tester<T,true>
{
static_assert(std::is_floating_point_v<T>);
+ static_assert(std::numeric_limits<T>::is_iec559);
bool operator()(T t)
{
// Here, nonstd::power() isn't preferable to pow(). This
@@ -187,17 +188,20 @@ namespace
(static_cast<T>(std::numeric_limits<T>::radix)
,static_cast<T>(std::numeric_limits<T>::digits)
);
- constexpr auto z1 = std::numeric_limits<long long int>::max();
+ constexpr auto z1lo = std::numeric_limits<long long int>::lowest();
+ constexpr auto z1hi = std::numeric_limits<long long int>::max();
#if defined __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wconversion"
# pragma GCC diagnostic ignored "-Wfloat-conversion"
#endif // defined __GNUC__
+ // As asserted above, 'z0' is of a floating type that
+ // conforms to IEEE 754, so '-z0' DTRT here.
return
- -z0 < t
- && t < z0
- && -z1 < t
- && t < z1
+ -z0 < t
+ && t < z0
+ && -z1lo < t
+ && t < z1hi
&& t == static_cast<long long int>(t)
;
#if defined __GNUC__