[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 8e69f1d 2/7: Don't write lowest() as "min()"
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 8e69f1d 2/7: Don't write lowest() as "min()" without asserting they're the same |
Date: |
Sat, 6 Mar 2021 17:55:54 -0500 (EST) |
branch: master
commit 8e69f1db4124fbb398e6607bb691217f3c49154c
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;
- [lmi-commits] [lmi] master updated (27b708a -> 7d2794b), Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 869de45 4/7: Fix defect introduced 20180319T1957Z: min() isn't lowest(), Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 7d2794b 7/7: Use minmax<T> iff std::numeric_limits<T>::is_bounded, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 5004bd4 5/7: Define 'minmax' of an empty vector, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master e23c058 6/7: Prefer data-member initializers to ctor delegation, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 24611b1 1/7: Improve a unit test, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 8e69f1d 2/7: Don't write lowest() as "min()" without asserting they're the same,
Greg Chicares <=
- [lmi-commits] [lmi] master 3330a9a 3/7: Don't write lowest() as "min()" even it they're the same, Greg Chicares, 2021/03/06