lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 1f03a06 5/7: Expunge max_stream_precision()


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 1f03a06 5/7: Expunge max_stream_precision()
Date: Tue, 27 Jun 2017 17:13:47 -0400 (EDT)

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

    Expunge max_stream_precision()
    
    As mentioned in the immediately-preceding commit message, this function
    and its header are no longer necessary because DECIMAL_DIG is in C++11.
---
 Makefile.am              |  1 -
 ledger_base.cpp          |  4 +---
 ledger_base.hpp          |  6 ++---
 max_stream_precision.hpp | 61 ------------------------------------------------
 pchlist.hpp              |  1 -
 5 files changed, 3 insertions(+), 70 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index a2135ae..340e64b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1181,7 +1181,6 @@ noinst_HEADERS = \
     map_lookup.hpp \
     materially_equal.hpp \
     math_functors.hpp \
-    max_stream_precision.hpp \
     mc_enum.hpp \
     mc_enum.tpp \
     mc_enum_aux.hpp \
diff --git a/ledger_base.cpp b/ledger_base.cpp
index 4592faf..e86fdb7 100644
--- a/ledger_base.cpp
+++ b/ledger_base.cpp
@@ -476,8 +476,6 @@ void LedgerBase::UpdateCRC(CRC& crc) const
 //============================================================================
 void LedgerBase::Spew(std::ostream& os) const
 {
-    static int const prec = max_stream_precision();
-
     for(auto const& i : AllVectors)
         {
         SpewVector(os, i.first, *i.second);
@@ -488,7 +486,7 @@ void LedgerBase::Spew(std::ostream& os) const
         os
             << i.first
             << "=="
-            << std::setprecision(prec) << *i.second
+            << std::setprecision(DECIMAL_DIG) << *i.second
             << '\n'
             ;
         }
diff --git a/ledger_base.hpp b/ledger_base.hpp
index 924edbe..3d48f37 100644
--- a/ledger_base.hpp
+++ b/ledger_base.hpp
@@ -24,11 +24,10 @@
 
 #include "config.hpp"
 
-#include "max_stream_precision.hpp"
 #include "so_attributes.hpp"
 
 #include <algorithm>
-#include <cfloat>
+#include <cfloat>                       // DECIMAL_DIG
 #include <functional>
 #include <iomanip>
 #include <ios>
@@ -245,9 +244,8 @@ template<typename T> void SpewVector
 {
     std::ostream_iterator<T> osi(os, "\n");
 
-    static int const prec = max_stream_precision();
     os << name << '\n';
-    os << std::setprecision(prec);
+    os << std::setprecision(DECIMAL_DIG);
     std::copy(elements.begin(), elements.end(), osi);
 }
 
diff --git a/max_stream_precision.hpp b/max_stream_precision.hpp
deleted file mode 100644
index 78953c7..0000000
--- a/max_stream_precision.hpp
+++ /dev/null
@@ -1,61 +0,0 @@
-// Precision for lossless floating-point I/O.
-//
-// Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 
2013, 2014, 2015, 2016, 2017 Gregory W. Chicares.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software Foundation,
-// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-//
-// http://savannah.nongnu.org/projects/lmi
-// email: <address@hidden>
-// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
-
-#ifndef max_stream_precision_hpp
-#define max_stream_precision_hpp
-
-#include "config.hpp"
-
-#include <cmath>
-#include <limits>
-
-/// Return the stream precision necessary to map any base-ten
-/// scientific-notation representation to binary and back without
-/// loss of accuracy.
-///
-/// Return a value of type int, rather than type std::streamsize .
-/// Rationale: this value is intended to be used with function
-///   std::ios_base::precision(std::streamsize)
-/// and manipulator
-///   std::setprecision(int)
-/// and its value can't plausibly exceed the range of an int, so it is
-/// preferable to avoid a narrowing conversion in the first use case.
-///
-/// Reference: c99 5.2.4.2.2/8 (DECIMAL_DIG), which isn't used here
-/// because it's not in c++98 .
-///
-/// INELEGANT !! Would it be better to make the type a template
-/// argument, and pass the stream as an argument so that
-/// we can make sure 'scientific' is set? How about making
-/// this a manipulator?
-
-inline int max_stream_precision()
-{
-    static const int nbits = std::numeric_limits<long double>::digits;
-    static const double precision =
-            1.0
-        +   std::ceil(std::log10(std::pow(2.0, nbits)))
-        ;
-    return static_cast<int>(precision);
-}
-
-#endif // max_stream_precision_hpp
-
diff --git a/pchlist.hpp b/pchlist.hpp
index bfd7d47..c1b8527 100644
--- a/pchlist.hpp
+++ b/pchlist.hpp
@@ -66,7 +66,6 @@
 #   include "ledger_invariant.hpp"
 #   include "ledger_variant.hpp"
 #   include "main_common.hpp"
-#   include "max_stream_precision.hpp"
 #   include "mc_enum.hpp"
 #   include "mc_enum_type_enums.hpp"
 #   include "mc_enum_types.hpp"



reply via email to

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