diff --git a/samples/distro-examples/tests/all.bas b/samples/distro-examples/tests/all.bas index cd38560c..496131af 100644 --- a/samples/distro-examples/tests/all.bas +++ b/samples/distro-examples/tests/all.bas @@ -140,7 +140,7 @@ print "DETERM:"' + DETERM (A, 1) print "DISCLOSE:" + DISCLOSE("{debraceme}", "{}") print "ENCLOSE:" + ENCLOSE ("braceme", "{}") print "EOF:"' + EOF (fileN) -print "EXIST:"' + EXIST (file) +print "EXIST:" + EXIST ("Makefile") print "EXP:" + EXP (x) print "FILES:"; FILES ("file-not-found") print "FIX:" + FIX (x) @@ -246,3 +246,4 @@ print "WEEKDAY:" + WEEKDAY(dmy) + " " + WEEKDAY(1,1,2020) + " " + WEEKDAY(JULIAN print "XPOS:" + XPOS print "YPOS:" + YPOS print "RoundPrecisionBug:"; 32.99999999999999 +print "RoundPrecisionBug2:"; 64.1 diff --git a/samples/distro-examples/tests/output/all.out b/samples/distro-examples/tests/output/all.out index 35bbaa26..67826935 100644 --- a/samples/distro-examples/tests/output/all.out +++ b/samples/distro-examples/tests/output/all.out @@ -123,7 +123,7 @@ DETERM: DISCLOSE:debraceme ENCLOSE:{braceme} EOF: -EXIST: +EXIST:1 EXP:219695.9886721379 FILES:[] FIX:13 @@ -229,3 +229,4 @@ WEEKDAY:-1 3 1 XPOS:0 YPOS:0 RoundPrecisionBug:33 +RoundPrecisionBug2:64.1 diff --git a/src/common/fmt.c b/src/common/fmt.c index 5131b8af..a2b8077c 100644 --- a/src/common/fmt.c +++ b/src/common/fmt.c @@ -20,16 +20,12 @@ #define FMT_xMIN 1e-8 #define FMT_xMAX 1e+14 #define FMT_RND 14 -#define FMT_xRND 1e+14 -#define FMT_xRND2 1e+13 #define FMT_MANTISSA_BITS 52 #else // limits for use with 32bit integer algorithm #define FMT_xMIN 1e-8 // lowest limit to use the exp. format #define FMT_xMAX 1e+9 // highest limit to use the exp. format #define FMT_RND 9 // rounding on x digits -#define FMT_xRND 1e+9 // 1 * 10 ^ FMT_RND -#define FMT_xRND2 1e+8 // 1 * 10 ^ (FMT_RND-1) #define FMT_MANTISSA_BITS 23 // Bits of mantissa for 32bit float #endif @@ -195,18 +191,13 @@ void bestfta_p(var_num_t x, char *dest, var_num_t minx, var_num_t maxx) { fptoa(ipart, buf); strcpy(d, buf); d += strlen(buf); - + if (fpart > 0.0) { // format right part *d++ = '.'; + fdif = fpart; - fdif = frac(x) * FMT_xRND; - if (fdif < fpart) { - // rounded value has greater precision - fdif = fpart; - } - - while (fdif < FMT_xRND2) { + while (fdif < pow(10, precision - 1)) { fdif *= 10; *d++ = '0'; }