lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master cab71af 3/3: Work around a MinGW-w64 gcc-7.2.


From: Greg Chicares
Subject: [lmi-commits] [lmi] master cab71af 3/3: Work around a MinGW-w64 gcc-7.2.0 anomaly
Date: Thu, 15 Mar 2018 11:24:31 -0400 (EDT)

branch: master
commit cab71afe9bdcfd1af3149aaf2c973ef6ee2040aa
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Work around a MinGW-w64 gcc-7.2.0 anomaly
    
    Reverted commits 1c1bafa402 and d584c2a02d, and suppressed a failing
    assertion.
    
    The d584c2a02d commit message said:
    | For integral N, log10(10^N) is not an exact integer.
    and that is true; but the problem here is that N was negative, so
    10^N was not an exact integer as might be expected for positive N.
    Thus, while it might be hoped that log10(1000) would return exactly 3,
    it is less certain that log10(0.001) exactly equals -3.
    
    Now that the nature of the problem is understood, the elaborate
    diagnostic message recently added is no longer wanted. The root cause,
    of course, is that 0.001 is reliably producible from 3, but 3 is not
    reliably recoverable from 0.001 .
---
 ledger_base.cpp | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/ledger_base.cpp b/ledger_base.cpp
index 2553a60..5814d6c 100644
--- a/ledger_base.cpp
+++ b/ledger_base.cpp
@@ -355,25 +355,12 @@ namespace
         double power = -std::log10(a_ScalingFactor);
         // Assert absolute equality of two floating-point quantities, because
         // they must both have integral values.
-        // PDF !! Fails with MinGW-w64 gcc-7.2.0 .
-        if(power != std::floor(power))
-            {
-            long double discrepancy0 = power - std::floor(power);
-            long double discrepancy1 = power - std::ceil (power);
-            warning()
-                << "Scaling factor is not an integral power of ten."
-                << "\n  " <<                        (power)             << " 
logarithm"
-                << "\n  " <<                        (std::floor(power)) << " 
floor()"
-                << "\n  " <<                        (std::trunc(power)) << " 
trunc()"
-                << "\n  " << value_cast<std::string>(power)             << " 
logarithm"
-                << "\n  " << value_cast<std::string>(std::floor(power)) << " 
floor()"
-                << "\n  " << value_cast<std::string>(std::trunc(power)) << " 
trunc()"
-                << "\n  " << value_cast<std::string>(discrepancy0) << " lower 
difference"
-                << "\n  " << value_cast<std::string>(discrepancy1) << " upper 
difference"
-                << LMI_FLUSH
-                ;
-            }
-//      LMI_ASSERT(power == std::floor(power));
+        // PDF !! Suppress the assertion because, with MinGW-w64 gcc-7.2.0,
+        // it fails--apparently floor() gives the wrong answer, but trunc()
+        // and static_cast<int>() give the right answer for the test case
+        // described in the git commit message for 1c1bafa40. Obviously this
+        // needs further work because the behavior in other cases is unknown.
+        // LMI_ASSERT(power == std::floor(power));
         int z = static_cast<int>(power);
 
         // US names are used; UK names are different.



reply via email to

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