lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 1bbeb957 1/5: Improve documentation


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 1bbeb957 1/5: Improve documentation
Date: Wed, 1 Jun 2022 17:06:25 -0400 (EDT)

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

    Improve documentation
    
    This looks like a superficial mistake. It might be tautological, but
    it's not superficial, and it's (now asserted to be) harmless, and it was
    deliberate--see commit 290dc8918d3892; and C99 [F.8.2] doesn't promise
    that 1/(1/x) → x.
---
 round_to_test.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/round_to_test.cpp b/round_to_test.cpp
index 22b3738e..bdcffa29 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -299,13 +299,15 @@ void round_to_test::test_various_float_types
     )
 {
     int const inverse_decimals = -decimals;
-    long double factor =
-        (0 <= inverse_decimals)
-        ?        bin_exp(10.0L,  inverse_decimals)
-        : 1.0L / bin_exp(10.0L, -inverse_decimals)
-        ;
-    long double u = unrounded * factor;
-    long double e = expected  * factor;
+    // The intention is to avoid taking the reciprocal of a reciprocal,
+    // but 'f0' and 'f1' appear to be equivalent, so perhaps that idea
+    // is too precious.
+    long double const f0 =        bin_exp(10.0L,  inverse_decimals);
+    long double const f1 = 1.0L / bin_exp(10.0L, -inverse_decimals);
+    LMI_TEST_EQUAL(f0, f1);
+    long double const factor = (0 <= inverse_decimals) ? f0 : f1;
+    long double const u = unrounded * factor;
+    long double const e = expected  * factor;
     LMI_TEST((test_one_case(static_cast<float >(u), static_cast<float >(e), 
decimals, style)));
     LMI_TEST((test_one_case(static_cast<double>(u), static_cast<double>(e), 
decimals, style)));
     LMI_TEST((test_one_case(/* long double */  (u), /* long double */  (e), 
decimals, style)));



reply via email to

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