From 5f7948e5a52b7c6e375b5fbe676578a8b8117de0 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Mon, 28 Jul 2014 00:33:13 +0200 Subject: [PATCH] Fix bugs 9190 and 9193. The conversion from floating point to string performed by boost:lexical_cast does not allow specifying a precision and, for example, values such as 0.9 are returned as 0.899999976. The standard C++ way for performing the conversion is using std::ostringstream which is exempt from this problem, even if less efficient. For the sake of accuracy, boost::lexical_cast is ditched in favor of the ostrinsgstream implementation. In C++11 another option would be using std::to_string, but I think it is not as efficient as the boost way and not worth implementing through #ifdef's. --- src/support/convert.cpp | 9 +++++++-- status.21x | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/support/convert.cpp b/src/support/convert.cpp index 70cd91eeba..6b985f50ba 100644 --- a/src/support/convert.cpp +++ b/src/support/convert.cpp @@ -17,6 +17,7 @@ #include #include +#include //needed for Mac OSX 10.5.2 Leopard #include @@ -106,14 +107,18 @@ docstring convert(long l) template<> string convert(float f) { - return lexical_cast(f); + std::ostringstream val; + val << f; + return val.str(); } template<> string convert(double d) { - return lexical_cast(d); + std::ostringstream val; + val << d; + return val.str(); } diff --git a/status.21x b/status.21x index be981c2ecb..e5b2cc38fc 100644 --- a/status.21x +++ b/status.21x @@ -87,6 +87,9 @@ What's new - Fix potential bug spotted by cppcheck. +- Fix problems arising when converting floating point values to the + corresponding string representation (bugs 9190 and 9193). + * DOCUMENTATION AND LOCALIZATION -- 2.39.5