lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 869de45 4/7: Fix defect introduced 20180319T1


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 869de45 4/7: Fix defect introduced 20180319T1957Z: min() isn't lowest()
Date: Sat, 6 Mar 2021 17:55:54 -0500 (EST)

branch: master
commit 869de452f861b9ae78528044c1971c3987ba4033
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Fix defect introduced 20180319T1957Z: min() isn't lowest()
    
    Fixed commit 3d3e2b67916c72 of 20180319T1957Z.
    
    * miscellany.hpp: Replace incorrect min() with correct lowest().
    * miscellany_test.cpp: Add a test that would fail with min().
---
 miscellany.hpp      | 2 +-
 miscellany_test.cpp | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/miscellany.hpp b/miscellany.hpp
index 0659730..8ab6f06 100644
--- a/miscellany.hpp
+++ b/miscellany.hpp
@@ -97,7 +97,7 @@ class minmax
   public:
     minmax()
         :minimum_ {std::numeric_limits<T>::max()}
-        ,maximum_ {std::numeric_limits<T>::min()}
+        ,maximum_ {std::numeric_limits<T>::lowest()}
         {
         }
 
diff --git a/miscellany_test.cpp b/miscellany_test.cpp
index 54d5803..19e25ff 100644
--- a/miscellany_test.cpp
+++ b/miscellany_test.cpp
@@ -25,6 +25,7 @@
 
 #include "test_tools.hpp"
 
+#include <cfloat>                       // DBL_MAX
 #include <cstdio>                       // remove()
 #include <fstream>
 #include <limits>
@@ -139,6 +140,11 @@ void test_minmax()
     w.push_back(one );
     w.push_back(zero);
 
+    // Test default ctor.
+    minmax<double> const dbl_minmax {};
+    LMI_TEST( DBL_MAX == dbl_minmax.minimum());
+    LMI_TEST(-DBL_MAX == dbl_minmax.maximum());
+
     // Test const-correctness.
     std::vector<double> const v = w;
     minmax<double> const m(v);



reply via email to

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