Skip to content
Snippets Groups Projects
Commit ee2516df authored by Gábor Szalai's avatar Gábor Szalai
Browse files

ttcn2str correction (bug 566118 & 566029)


The number of the significant digits used during the code generation
is increased to 17

The string representation of the float generated by the ttcn2str is
corrected: no leading zero in exponent, 17 significant digits

Change-Id: Ib49b878a78c87c1a8fee55b06c9b713023e90797
Signed-off-by: default avatarGabor Szalai <gabor.szalai@ericsson.com>
parent bcab9cf8
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@ namespace Common {
double integral = floor(fraction);
char tmp[64];
sprintf(tmp, "%s%.15g%se%d",
sprintf(tmp, "%s%.17g%se%d",
(sign == -1) ? "-" : "",
fraction,
(fraction == integral) ? ".0" : "",
......@@ -68,7 +68,7 @@ namespace Common {
Real exponent = floor(log10(rabs));
Real mantissa = rabs * pow(10.0, -exponent);
char *tmp = mprintf("%s%.15g", r < 0.0 ? "-" : "", mantissa);
char *tmp = mprintf("%s%.17g", r < 0.0 ? "-" : "", mantissa);
if (floor(mantissa) == mantissa) tmp = mputstr(tmp, ".0");
if (exponent != 0.0) tmp = mputprintf(tmp, "e%d", (int)exponent);
string ret_val(tmp);
......
......@@ -68,12 +68,28 @@ static inline void log_float(double float_val)
else if(float_val!=float_val)
TTCN_Logger::log_event_str("not_a_number");
else {
boolean f = (float_val > -MAX_DECIMAL_FLOAT && float_val <= -MIN_DECIMAL_FLOAT)
|| (float_val >= MIN_DECIMAL_FLOAT && float_val < MAX_DECIMAL_FLOAT)
|| (float_val == 0.0);
const char* loc = setlocale(LC_ALL, NULL);
setlocale(LC_NUMERIC, "C"); // use default locale for displaying numbers
TTCN_Logger::log_event(f ? "%f" : "%e", float_val);
if(TTCN_Logger::get_log_format() == TTCN_Logger::LF_TTCN && float_val != 0.0){
// ttcn2str, use the TTCN-3 standard format and print enough
// digits so when scanning the string back, we get the original floating point.
// for 64bit double 17 digit is needed
// The 0.0 is habdled by the normal logging case. The %f prints the 0.0 or -0.0 correctly
double rabs = fabs(float_val);
double exponent = floor(log10(rabs));
double mantissa = rabs * pow(10.0, -exponent);
TTCN_Logger::log_event("%s%.17g", float_val < 0.0 ? "-" : "", mantissa);
if (floor(mantissa) == mantissa) TTCN_Logger::log_event( ".0");
if (exponent != 0.0) TTCN_Logger::log_event("e%d", (int)exponent);
} else {
// Normal logging
boolean f = (float_val > -MAX_DECIMAL_FLOAT && float_val <= -MIN_DECIMAL_FLOAT)
|| (float_val >= MIN_DECIMAL_FLOAT && float_val < MAX_DECIMAL_FLOAT)
|| (float_val == 0.0);
TTCN_Logger::log_event(f ? "%f" : "%e", float_val);
}
setlocale(LC_NUMERIC, loc);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment