From 67c52ae7738b2ac3b4bd35af6cf9c65e05f84cd8 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Fri, 26 Jun 2015 22:49:17 +0200 Subject: [PATCH] Amend c9d9309c It suffices taking the log of the absolute value. --- src/support/lstrings.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index 6faf1a4fc3..3b903c83de 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -1408,10 +1408,7 @@ std::string formatFPNumber(double x) // Prevent outputs of 23.4200000000000017 but output small numbers // with at least 6 significant digits. bool const neg = x < 0; - // Treat all doubles as positive for the formatting - if (neg) - x = -x; - double const logarithm = log10(x); + double const logarithm = log10(abs(x)); os << std::setprecision(max(6 - static_cast(round(logarithm)), 0)) << x; string result = os.str(); if (result.find('.') != string::npos) { @@ -1419,9 +1416,6 @@ std::string formatFPNumber(double x) if (result[result.length()-1] == '.') result = rtrim(result, "."); } - // Re-add negativity - if (neg) - result = "-" + result; return result; }