Commit 77bdf234 authored by Gábor Szalai's avatar Gábor Szalai
Browse files

Reduce the float printout precision (bug 566118)



The 17 digit precision was too precise for the float.
The 17 significant digit ensured that the parsed back value is
the same as the original, but the currently used print out function
introduced rounding errors, which renders the last digit useless.

Further development and experiment is needed, because neither functionality
provided by the c++ library prints the float as expected by the TTCN standard.

Change-Id: I328e8ed423c7d96f2ee46e5453e090a1c3fda6a8
Signed-off-by: Gábor Szalai's avatarGabor Szalai <gabor.szalai@ericsson.com>
parent ceb4929b
...@@ -48,7 +48,7 @@ namespace Common { ...@@ -48,7 +48,7 @@ namespace Common {
double integral = floor(fraction); double integral = floor(fraction);
char tmp[64]; char tmp[64];
sprintf(tmp, "%s%.17g%se%d", sprintf(tmp, "%s%.16g%se%d",
(sign == -1) ? "-" : "", (sign == -1) ? "-" : "",
fraction, fraction,
(fraction == integral) ? ".0" : "", (fraction == integral) ? ".0" : "",
...@@ -68,7 +68,7 @@ namespace Common { ...@@ -68,7 +68,7 @@ namespace Common {
Real exponent = floor(log10(rabs)); Real exponent = floor(log10(rabs));
Real mantissa = rabs * pow(10.0, -exponent); Real mantissa = rabs * pow(10.0, -exponent);
char *tmp = mprintf("%s%.17g", r < 0.0 ? "-" : "", mantissa); char *tmp = mprintf("%s%.16g", r < 0.0 ? "-" : "", mantissa);
if (floor(mantissa) == mantissa) tmp = mputstr(tmp, ".0"); if (floor(mantissa) == mantissa) tmp = mputstr(tmp, ".0");
if (exponent != 0.0) tmp = mputprintf(tmp, "e%d", (int)exponent); if (exponent != 0.0) tmp = mputprintf(tmp, "e%d", (int)exponent);
string ret_val(tmp); string ret_val(tmp);
......
...@@ -79,7 +79,7 @@ static inline void log_float(double float_val) ...@@ -79,7 +79,7 @@ static inline void log_float(double float_val)
double exponent = floor(log10(rabs)); double exponent = floor(log10(rabs));
double mantissa = rabs * pow(10.0, -exponent); double mantissa = rabs * pow(10.0, -exponent);
TTCN_Logger::log_event("%s%.17g", float_val < 0.0 ? "-" : "", mantissa); TTCN_Logger::log_event("%s%.16g", float_val < 0.0 ? "-" : "", mantissa);
if (floor(mantissa) == mantissa) TTCN_Logger::log_event( ".0"); if (floor(mantissa) == mantissa) TTCN_Logger::log_event( ".0");
if (exponent != 0.0) TTCN_Logger::log_event("e%d", (int)exponent); if (exponent != 0.0) TTCN_Logger::log_event("e%d", (int)exponent);
......
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