[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master eb90054 4/7: Do not use value_cast in decimal
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master eb90054 4/7: Do not use value_cast in decimal_root() |
Date: |
Tue, 27 Jun 2017 17:13:47 -0400 (EDT) |
branch: master
commit eb900545f2e13a3eb6d19220777c711d30d948bd
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Do not use value_cast in decimal_root()
This change improved the measured speed of mete_dob_limit() about
sevenfold with i686-w64-mingw32-gcc-4.9.1 by skipping needless work
when writing successive iterands to the default null stream. Reason:
built-in stream inserters exit before performing any formatting when
'badbit' is set, but the (replaced) calls to value_cast<>() could not
be short-circuited in that way.
Setting precision to a large enough value to preserve all information
(i.e., DECIMAL_DIG) is about as good as using value_cast in this case.
Incidentally, 'max_stream_precision.hpp' is no longer needed now that
DECIMAL_DIG is now part of standard C++.
Stream output could be made a little faster by writing a newline
character instead of std::endl. That idea was not used because it
might cause useful information to be lost if the objective function
throws, and because all stream output can be suppressed in the default
null-stream case by making output conditional on 'badbit'.
---
zero.hpp | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/zero.hpp b/zero.hpp
index 6245c1b..af71c93 100644
--- a/zero.hpp
+++ b/zero.hpp
@@ -26,8 +26,8 @@
#include "null_stream.hpp"
#include "round_to.hpp"
-#include "value_cast.hpp"
+#include <cfloat> // DECIMAL_DIG
#include <cmath>
#include <limits>
#include <ostream>
@@ -241,6 +241,8 @@ root_type decimal_root
,std::ostream& iteration_stream = null_stream()
)
{
+ iteration_stream.precision(DECIMAL_DIG);
+
static double const epsilon = std::numeric_limits<double>::epsilon();
int number_of_iterations = 0;
@@ -255,8 +257,8 @@ root_type decimal_root
double fa = static_cast<double>(f(a));
iteration_stream
<< "iteration " << number_of_iterations++
- << " iterand " << value_cast<std::string>(a)
- << " value " << value_cast<std::string>(fa)
+ << " iterand " << a
+ << " value " << fa
<< std::endl
;
if(0.0 == fa)
@@ -267,8 +269,8 @@ root_type decimal_root
double fb = static_cast<double>(f(b));
iteration_stream
<< "iteration " << number_of_iterations++
- << " iterand " << value_cast<std::string>(b)
- << " value " << value_cast<std::string>(fb)
+ << " iterand " << b
+ << " value " << fb
<< std::endl
;
double last_evaluated_iterand = b; // Note 1.
@@ -401,8 +403,8 @@ root_type decimal_root
last_evaluated_iterand = b;
iteration_stream
<< "iteration " << number_of_iterations++
- << " iterand " << value_cast<std::string>(b)
- << " value " << value_cast<std::string>(fb)
+ << " iterand " << b
+ << " value " << fb
<< std::endl
;
}
- [lmi-commits] [lmi] master updated (84e96df -> 47d6100), Greg Chicares, 2017/06/27
- [lmi-commits] [lmi] master b4420a3 3/7: Fix misspellings, Greg Chicares, 2017/06/27
- [lmi-commits] [lmi] master 7a09c77 2/7: Set 'badbit' for null stream, Greg Chicares, 2017/06/27
- [lmi-commits] [lmi] master eb90054 4/7: Do not use value_cast in decimal_root(),
Greg Chicares <=
- [lmi-commits] [lmi] master c80737e 1/7: Measure minimum_birthdate() speed in unit test, Greg Chicares, 2017/06/27
- [lmi-commits] [lmi] master 47d6100 7/7: Suppress all output to null stream in decimal_root(), Greg Chicares, 2017/06/27
- [lmi-commits] [lmi] master 1f03a06 5/7: Expunge max_stream_precision(), Greg Chicares, 2017/06/27
- [lmi-commits] [lmi] master f4d2b2c 6/7: Include headers iff used, stating reasons if not obvious, Greg Chicares, 2017/06/27