lmi-commits
[Top][All Lists]
Advanced

[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()



reply via email to

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