Commit 283ba970 authored by Alexander A. Maly's avatar Alexander A. Maly

Default real numbers output precision improved.

It is now 1+13 significant digits in total, to prevent "strange" results when printing values like 0.1 and to round DBL_MAX down.
parent bdc0e064
Pipeline #701 passed with stages
in 4 minutes and 17 seconds
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <string> #include <string>
#include <cmath> #include <cmath>
#include <cfloat>
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
# include <Windows.h> # include <Windows.h>
...@@ -907,23 +908,31 @@ public: ...@@ -907,23 +908,31 @@ public:
return result; return result;
} }
static String sprintfReal(real value, Char dot, bool expform, int width, int decimals, char al) { static String sprintfReal(
std::stringstream stream; real value, Char dot, bool expform,
if (0 > decimals && !expform) { int width, int decimals, char al
) {
int sdecimals = decimals;
if (sdecimals < 0) {
double absVal = fabs(double(value)); double absVal = fabs(double(value));
if (0.0 != value && (absVal < 0.0001 || absVal > 999999.)) sdecimals = 13;
expform = true; if (0 < absVal && absVal <= DBL_MAX) {
if (absVal < 1e-4 || absVal >= 1e6) {
expform = true;
}
if (!expform) {
sdecimals -= ::floor(::log(absVal) / ::log(10.0));
}
}
} }
std::stringstream stream;
if (expform) { if (expform) {
stream << std::scientific; stream << std::scientific;
// stream.precision(2); } else {
stream.precision(0>decimals ? 6 : decimals);
}
else {
stream << std::fixed; stream << std::fixed;
stream.precision(0>decimals ? 6 : decimals);
} }
stream.precision(sdecimals < 0 ? 6 : sdecimals);
stream << value; stream << value;
std::string rpart = stream.str(); std::string rpart = stream.str();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment