lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 8b6d6dd8 12/13: Say DECIMAL_DIG wherever it's


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 8b6d6dd8 12/13: Say DECIMAL_DIG wherever it's meant
Date: Mon, 9 May 2022 20:13:18 -0400 (EDT)

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

    Say DECIMAL_DIG wherever it's meant
    
    "21" is not descriptive, and std::numeric_limits<T>::max_digits10 is
    abominable.
---
 irc7702_tables_test.cpp | 8 ++++----
 null_stream_test.cpp    | 3 ++-
 ul_utilities.cpp        | 4 ++--
 ul_utilities_test.cpp   | 3 ++-
 zero_test.cpp           | 6 +++---
 5 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/irc7702_tables_test.cpp b/irc7702_tables_test.cpp
index 73df722b..fc6661dd 100644
--- a/irc7702_tables_test.cpp
+++ b/irc7702_tables_test.cpp
@@ -30,7 +30,7 @@
 #include "ssize_lmi.hpp"
 #include "test_tools.hpp"
 
-#include <cfloat>                       // DBL_EPSILON
+#include <cfloat>                       // DBL_EPSILON, DECIMAL_DIG
 #include <cmath>                        // log()
 #include <vector>
 
@@ -1042,7 +1042,7 @@ void irc7702_tables_test::test_1980_cso()
 
     double const observed = ol_nsp[0];
     double const expected = olcf_1980_cso_endt_100[0].Ax;
-    std::cout.precision(21);
+    std::cout.precision(DECIMAL_DIG);
     std::cout
         << "Initial Ax (the most sensitive value) for 1980 CSO:"
         << "\n  spreadsheet:    " << expected
@@ -1086,7 +1086,7 @@ void irc7702_tables_test::test_2001_cso()
 
     double const observed = ol_nsp[0];
     double const expected = olcf_2001_cso_endt_100[0].Ax;
-    std::cout.precision(21);
+    std::cout.precision(DECIMAL_DIG);
     std::cout
         << "Initial Ax (the most sensitive value) for 2001 CSO:"
         << "\n  spreadsheet:    " << expected
@@ -1130,7 +1130,7 @@ void irc7702_tables_test::test_2017_cso()
 
     double const observed = ol_nsp[0];
     double const expected = olcf_2017_cso_endt_95[0].Ax;
-    std::cout.precision(21);
+    std::cout.precision(DECIMAL_DIG);
     std::cout
         << "Initial Ax (the most sensitive value) for 2017 CSO:"
         << "\n  spreadsheet:    " << expected
diff --git a/null_stream_test.cpp b/null_stream_test.cpp
index 2945070f..2ef80d10 100644
--- a/null_stream_test.cpp
+++ b/null_stream_test.cpp
@@ -27,6 +27,7 @@
 #include "test_tools.hpp"
 #include "timer.hpp"
 
+#include <cfloat>                       // DECIMAL_DIG
 #include <fstream>
 #include <iomanip>
 #include <sstream>
@@ -68,7 +69,7 @@ void emit_text_to_stream(std::ostream& os)
             << std::flush
             ;
         os
-            << std::setprecision(21)
+            << std::setprecision(DECIMAL_DIG)
             << std::setw(12) << 3.14159
             << std::fixed
             << std::hex
diff --git a/ul_utilities.cpp b/ul_utilities.cpp
index 8e681e6c..744007b5 100644
--- a/ul_utilities.cpp
+++ b/ul_utilities.cpp
@@ -125,8 +125,8 @@ currency rate_times_currency
     if(!materially_equal(bourn_cast<double>(irate), rate * radix))
         {
 #if 0
-        // Enable this (including <iostream>) for research.
-        std::cout.precision(21);
+        // Enable this (including <iostream> and <cfloat>) for research.
+        std::cout.precision(DECIMAL_DIG);
         std::cout
             << "Excessive precision in rate; check the table\n"
             << bourn_cast<double>(irate) << " bourn_cast<double>(irate)\n"
diff --git a/ul_utilities_test.cpp b/ul_utilities_test.cpp
index f2767965..6c76340a 100644
--- a/ul_utilities_test.cpp
+++ b/ul_utilities_test.cpp
@@ -29,13 +29,14 @@
 #include "test_tools.hpp"
 
 #include <cfenv>                        // fesetround()
+#include <cfloat>                       // DECIMAL_DIG
 #include <cmath>                        // nearbyint()
 #include <cstdint>                      // int64_t
 
 void test_max_modal_premium()
 {
     // This affects diagnostics shown when LMI_TEST_EQUAL() fails.
-    std::cout.precision(21);
+    std::cout.precision(DECIMAL_DIG);
 
     // These are generally useful for testing.
     round_to<double> const round_down(2, r_downward);
diff --git a/zero_test.cpp b/zero_test.cpp
index c9f26d95..2256e3e4 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -861,7 +861,7 @@ void test_celebrated_equation()
     auto f = [](double x) {return x * x * x - 2.0 * x - 5.0;};
     std::ostringstream oss;
     oss.precision(17);
-    root_type r = decimal_root(f, -2.56, 2.56, bias_none, 21, oss);
+    root_type r = decimal_root(f, -2.56, 2.56, bias_none, DECIMAL_DIG, oss);
     LMI_TEST(root_is_valid == r.validity);
     // This constant is from the cited blog; lmi yields this,
     // which agrees to sixteen significant digits:
@@ -1360,7 +1360,7 @@ b = 1;
 
 //  s_stop("", (ftnlen)0);
 //std::cout << "Number of evaluations = " << n_eval << std::endl;
-//std::cout.precision(21);
+//std::cout.precision(DECIMAL_DIG);
 //std::cout << "Computed root = " << root << std::endl;
     } // end test adapted from 'driver.f'
 
@@ -1374,7 +1374,7 @@ b = 1;
 
     auto f = [](double x) {return std::sin(x) - x / 2.0;};
 
-    std::cout.precision(21);
+    std::cout.precision(DECIMAL_DIG);
 
     root_type r = lmi_root(f, bound0, bound1, 0.0);
     double const validated = r.root;



reply via email to

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