]> git.lyx.org Git - features.git/commitdiff
Fix bugs 9190 and 9193.
authorEnrico Forestieri <forenr@lyx.org>
Sun, 27 Jul 2014 22:33:13 +0000 (00:33 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 27 Jul 2014 22:33:13 +0000 (00:33 +0200)
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
status.21x

index 70cd91eebafd15ac9ebf00baa3c4c3f48541edd6..6b985f50baf26042d972fa8d4ea8f70127763ea1 100644 (file)
@@ -17,6 +17,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include <string>
+#include <sstream>
 //needed for Mac OSX 10.5.2 Leopard
 #include <cstdlib>
 
@@ -106,14 +107,18 @@ docstring convert<docstring>(long l)
 template<>
 string convert<string>(float f)
 {
-       return lexical_cast<string>(f);
+       std::ostringstream val;
+       val << f;
+       return val.str();
 }
 
 
 template<>
 string convert<string>(double d)
 {
-       return lexical_cast<string>(d);
+       std::ostringstream val;
+       val << d;
+       return val.str();
 }
 
 
index be981c2ecb57375267100d38c252a739bf5b67b0..e5b2cc38fc698b0816a8655e4c07886652d064ab 100644 (file)
@@ -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