[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);
- [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 <=
- [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, 2021/03/06
- [lmi-commits] [lmi] master 3330a9a 3/7: Don't write lowest() as "min()" even it they're the same, Greg Chicares, 2021/03/06