lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] odd/eraseme_limits e43dd18 2/6: Don't write lowest()


From: Greg Chicares
Subject: [lmi-commits] [lmi] odd/eraseme_limits e43dd18 2/6: Don't write lowest() as "min()" without asserting they're the same
Date: Sat, 6 Mar 2021 17:57:41 -0500 (EST)

branch: odd/eraseme_limits
commit e43dd1828cc30bc5afbcbeeae0d24e32c0549aac
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Don't write lowest() as "min()" without asserting they're the same
---
 math_functions.hpp |  5 +++++
 monnaie_test.cpp   |  5 +++++
 tn_range.tpp       | 10 +++++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/math_functions.hpp b/math_functions.hpp
index b39090b..bc6d59d 100644
--- a/math_functions.hpp
+++ b/math_functions.hpp
@@ -101,6 +101,11 @@ inline T outward_quotient(T numerator, T denominator)
 
     // "INT_MIN / -1" would overflow; but "false/bool(-1)" would not,
     // hence the "T(-1) < 0" test.
+    // Make sure min() means lowest().
+    static_assert
+        (  std::numeric_limits<T>::min()
+        == std::numeric_limits<T>::lowest()
+        );
     constexpr T min = std::numeric_limits<T>::min();
     if(min == numerator && T(-1) < 0 && T(-1) == denominator)
         {
diff --git a/monnaie_test.cpp b/monnaie_test.cpp
index de86a11..a580f1b 100644
--- a/monnaie_test.cpp
+++ b/monnaie_test.cpp
@@ -91,6 +91,11 @@ void monnaie_test::test_ctors()
         ,std::overflow_error
         ,overflow_msg
         );
+    // Make sure min() means lowest().
+    static_assert
+        (  std::numeric_limits<monnaie::amount_type>::min()
+        == std::numeric_limits<monnaie::amount_type>::lowest()
+        );
     LMI_TEST_THROW
         (monnaie(std::numeric_limits<monnaie::amount_type>::min(), 0)
         ,std::overflow_error
diff --git a/tn_range.tpp b/tn_range.tpp
index 749f90d..1ed1221 100644
--- a/tn_range.tpp
+++ b/tn_range.tpp
@@ -68,13 +68,21 @@ namespace
     };
 
     // Type is fundamental but not floating, and therefore integral
-    // (or void, which would naturally be improper).
+    // (or void, which would naturally be improper). The static
+    // assertions are at worst O(1) pleonasms.
 
     template<typename T>
     struct strictly_between_extrema_tester<T,true,false>
     {
         bool operator()(T t)
             {
+            static_assert(std::numeric_limits<T>::is_bounded);
+            static_assert(!std::is_floating_point_v<T>);
+            // Make sure min() means lowest().
+            static_assert
+                (  std::numeric_limits<T>::min()
+                == std::numeric_limits<T>::lowest()
+                );
             static T const lower_limit = std::numeric_limits<T>::min();
             static T const upper_limit = std::numeric_limits<T>::max();
             return lower_limit < t && t < upper_limit;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]