Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion samples/distro-examples/tests/all.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion samples/distro-examples/tests/output/all.out
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ DETERM:
DISCLOSE:debraceme
ENCLOSE:{braceme}
EOF:
EXIST:
EXIST:1
EXP:219695.9886721379
FILES:[]
FIX:13
Expand Down Expand Up @@ -229,3 +229,4 @@ WEEKDAY:-1 3 1
XPOS:0
YPOS:0
RoundPrecisionBug:33
RoundPrecisionBug2:64.1
15 changes: 3 additions & 12 deletions src/common/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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';
}
Expand Down