lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master cecc91f 21/23: Avoid a unit-test false negati


From: Greg Chicares
Subject: [lmi-commits] [lmi] master cecc91f 21/23: Avoid a unit-test false negative
Date: Tue, 27 Jul 2021 21:59:54 -0400 (EDT)

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

    Avoid a unit-test false negative
    
    There are many binary64 values x for which cos(x) - 0.999 exactly equals
    zero due to roundoff error.
---
 zero_test.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/zero_test.cpp b/zero_test.cpp
index 29a2333..d1fa18f 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -870,8 +870,15 @@ void test_various_functions()
     test_a_function        (f02, root_02, 0.0, 2.0, 1.0e-15, __LINE__);
 
     auto f03 = [](double x) {return std::cos(x) - 0.999;};
-    auto root_03 = 0.044725087168733454;
-    test_a_decimal_function(f03, root_03, -0.01, 0.8, 17     , __LINE__, 16);
+// This would seem preferable:
+//  auto root_03 = std::acosl(0.999L);
+// but gcc-10.2.0 (x86_64-pc-linux-gnu) rejects it:
+//    error: ‘acosl’ is not a member of ‘std’
+// despite C++20 [cmath.syn], so use this instead:
+    auto root_03 = std::acos(0.999);
+// Regardless of that theoretical ζ, the computed ζ′ is not exact
+// to more than about fifteen decimals.
+    test_a_decimal_function(f03, root_03, -0.01, 0.8, 15     , __LINE__, 16);
     test_a_function        (f03, root_03, -0.01, 0.8, 1.0e-15, __LINE__);
 
     auto f04 = [](double x) {return std::pow((x - 1.0), 3);};



reply via email to

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