lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 358c5c9 06/13: Modernize


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 358c5c9 06/13: Modernize
Date: Fri, 9 Apr 2021 18:42:37 -0400 (EDT)

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

    Modernize
    
    C99 can be assumed and need no longer be emulated.
---
 round_test.cpp    | 9 ++-------
 round_to_test.cpp | 9 ++-------
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/round_test.cpp b/round_test.cpp
index 1bc9011..215a25f 100644
--- a/round_test.cpp
+++ b/round_test.cpp
@@ -39,6 +39,7 @@
 #include "test_tools.hpp"
 
 #include <algorithm>                    // max()
+#include <cfloat>                       // DECIMAL_DIG
 #include <cmath>                        // round()
 #include <ios>
 #include <iostream>
@@ -203,13 +204,7 @@ bool test_one_case
     if(!error_is_within_tolerance)
         {
         std::cout << '\n';
-        // Use enough precision to map the base-ten scientific
-        // representation back to binary without loss of accuracy.
-        // Cf. C99 5.2.4.2.2/8 (DECIMAL_DIG).
-        int nbits = std::numeric_limits<RealType>::digits;
-        std::streamsize old_precision = std::cout.precision
-            (1 + static_cast<int>(std::ceil(std::log10(std::pow(2.0, nbits))))
-            );
+        std::streamsize old_precision = std::cout.precision(DECIMAL_DIG);
         std::ios_base::fmtflags old_flags = std::cout.flags();
 
         std::cout
diff --git a/round_to_test.cpp b/round_to_test.cpp
index ca45a1a..54c5db8 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -29,6 +29,7 @@
 #include "test_tools.hpp"
 
 #include <algorithm>                    // max()
+#include <cfloat>                       // DECIMAL_DIG
 #include <climits>                      // INT_MIN
 #include <ios>
 #include <iostream>
@@ -243,13 +244,7 @@ bool round_to_test::test_one_case
     if(!error_is_within_tolerance)
         {
         std::cout << '\n';
-        // Use enough precision to map the base-ten scientific
-        // representation back to binary without loss of accuracy.
-        // Cf. C99 5.2.4.2.2/8 (DECIMAL_DIG).
-        int nbits = std::numeric_limits<RealType>::digits;
-        std::streamsize old_precision = std::cout.precision
-            (1 + static_cast<int>(std::ceil(std::log10(std::pow(2.0, nbits))))
-            );
+        std::streamsize old_precision = std::cout.precision(DECIMAL_DIG);
         std::ios_base::fmtflags old_flags = std::cout.flags();
 
         std::cout



reply via email to

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