[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 08ec6337 4/8: Genericize relative_error()
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 08ec6337 4/8: Genericize relative_error() |
Date: |
Fri, 17 Jun 2022 17:16:28 -0400 (EDT) |
branch: master
commit 08ec633732848517978f0cac0aa46b0011fffead
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Genericize relative_error()
---
math_functions.hpp | 4 ++--
math_functions_test.cpp | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/math_functions.hpp b/math_functions.hpp
index e7713c99..e1eded1a 100644
--- a/math_functions.hpp
+++ b/math_functions.hpp
@@ -123,8 +123,8 @@ template<typename T>
constexpr T inf {std::numeric_limits<T>::infinity()};
auto const denominator {std::min(std::fabs(t), std::fabs(u))};
return
- (0.0 == t && 0.0 == u) ? 0.0
- : (0.0 == denominator) ? inf
+ (T{} == t && T{} == u) ? T{}
+ : (T{} == denominator) ? inf
: std::fabs(t - u) / denominator
;
}
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 12a91a40..e3072169 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -493,6 +493,9 @@ void test_relative_error()
LMI_TEST_EQUAL(2.0, relative_error(1.0, -1.0));
LMI_TEST_EQUAL(big, relative_error(1.0, big));
LMI_TEST_EQUAL(inf, relative_error(big, -big));
+
+ LMI_TEST_EQUAL(2.0F, relative_error(1.0F, -1.0F));
+ LMI_TEST_EQUAL(2.0L, relative_error(1.0L, -1.0L));
}
void test_signed_zero()
- [lmi-commits] [lmi] master updated (7d0257a3 -> 876d4b5b), Greg Chicares, 2022/06/17
- [lmi-commits] [lmi] master bcd3e721 2/8: Make relative-error function generally available, Greg Chicares, 2022/06/17
- [lmi-commits] [lmi] master ac211c61 7/8: Write DECIMAL_DIG where it's obviously intended, Greg Chicares, 2022/06/17
- [lmi-commits] [lmi] master 876d4b5b 8/8: Remove unhelpful defect markers [265], Greg Chicares, 2022/06/17
- [lmi-commits] [lmi] master 79298e8c 1/8: Avoid left shift of a negative signed integer in fdlibm, Greg Chicares, 2022/06/17
- [lmi-commits] [lmi] master 08ec6337 4/8: Genericize relative_error(),
Greg Chicares <=
- [lmi-commits] [lmi] master 4eb11e23 5/8: Use relative_error, Greg Chicares, 2022/06/17
- [lmi-commits] [lmi] master 8dfc0348 6/8: Remove an obsolete comment, Greg Chicares, 2022/06/17
- [lmi-commits] [lmi] master 0c922cb6 3/8: Rename rel_err() --> relative_error(), Greg Chicares, 2022/06/17