Skip to content

Commit e55c8c7

Browse files
authored
Merge pull request #196 from Joe7M/master
Fix for RoundPrecisionBug 2
2 parents ad194da + 354417a commit e55c8c7

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

samples/distro-examples/tests/all.bas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ print "DETERM:"' + DETERM (A, 1)
140140
print "DISCLOSE:" + DISCLOSE("{debraceme}", "{}")
141141
print "ENCLOSE:" + ENCLOSE ("braceme", "{}")
142142
print "EOF:"' + EOF (fileN)
143-
print "EXIST:"' + EXIST (file)
143+
print "EXIST:" + EXIST ("Makefile")
144144
print "EXP:" + EXP (x)
145145
print "FILES:"; FILES ("file-not-found")
146146
print "FIX:" + FIX (x)
@@ -246,3 +246,4 @@ print "WEEKDAY:" + WEEKDAY(dmy) + " " + WEEKDAY(1,1,2020) + " " + WEEKDAY(JULIAN
246246
print "XPOS:" + XPOS
247247
print "YPOS:" + YPOS
248248
print "RoundPrecisionBug:"; 32.99999999999999
249+
print "RoundPrecisionBug2:"; 64.1

samples/distro-examples/tests/output/all.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ DETERM:
123123
DISCLOSE:debraceme
124124
ENCLOSE:{braceme}
125125
EOF:
126-
EXIST:
126+
EXIST:1
127127
EXP:219695.9886721379
128128
FILES:[]
129129
FIX:13
@@ -229,3 +229,4 @@ WEEKDAY:-1 3 1
229229
XPOS:0
230230
YPOS:0
231231
RoundPrecisionBug:33
232+
RoundPrecisionBug2:64.1

src/common/fmt.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@
2020
#define FMT_xMIN 1e-8
2121
#define FMT_xMAX 1e+14
2222
#define FMT_RND 14
23-
#define FMT_xRND 1e+14
24-
#define FMT_xRND2 1e+13
2523
#define FMT_MANTISSA_BITS 52
2624
#else
2725
// limits for use with 32bit integer algorithm
2826
#define FMT_xMIN 1e-8 // lowest limit to use the exp. format
2927
#define FMT_xMAX 1e+9 // highest limit to use the exp. format
3028
#define FMT_RND 9 // rounding on x digits
31-
#define FMT_xRND 1e+9 // 1 * 10 ^ FMT_RND
32-
#define FMT_xRND2 1e+8 // 1 * 10 ^ (FMT_RND-1)
3329
#define FMT_MANTISSA_BITS 23 // Bits of mantissa for 32bit float
3430
#endif
3531

@@ -195,18 +191,13 @@ void bestfta_p(var_num_t x, char *dest, var_num_t minx, var_num_t maxx) {
195191
fptoa(ipart, buf);
196192
strcpy(d, buf);
197193
d += strlen(buf);
198-
194+
199195
if (fpart > 0.0) {
200196
// format right part
201197
*d++ = '.';
198+
fdif = fpart;
202199

203-
fdif = frac(x) * FMT_xRND;
204-
if (fdif < fpart) {
205-
// rounded value has greater precision
206-
fdif = fpart;
207-
}
208-
209-
while (fdif < FMT_xRND2) {
200+
while (fdif < pow(10, precision - 1)) {
210201
fdif *= 10;
211202
*d++ = '0';
212203
}

0 commit comments

Comments
 (0)