From 367d9248530b09441752cc1583685ea2da36a051 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen Date: Sun, 14 May 2023 16:11:04 +0200 Subject: [PATCH 1/2] Fix floating-point number round-precision bug when converting a floating-point number to string. --- samples/distro-examples/tests/all.bas | 1 + samples/distro-examples/tests/output/all.out | 1 + src/common/fmt.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/distro-examples/tests/all.bas b/samples/distro-examples/tests/all.bas index 8af5ebe1..cd38560c 100644 --- a/samples/distro-examples/tests/all.bas +++ b/samples/distro-examples/tests/all.bas @@ -245,3 +245,4 @@ print "VAL:" + VAL (s) print "WEEKDAY:" + WEEKDAY(dmy) + " " + WEEKDAY(1,1,2020) + " " + WEEKDAY(JULIAN(d,m,y)) print "XPOS:" + XPOS print "YPOS:" + YPOS +print "RoundPrecisionBug:"; 32.99999999999999 diff --git a/samples/distro-examples/tests/output/all.out b/samples/distro-examples/tests/output/all.out index 30ed6627..35bbaa26 100644 --- a/samples/distro-examples/tests/output/all.out +++ b/samples/distro-examples/tests/output/all.out @@ -228,3 +228,4 @@ VAL:0 WEEKDAY:-1 3 1 XPOS:0 YPOS:0 +RoundPrecisionBug:33 diff --git a/src/common/fmt.c b/src/common/fmt.c index 39125610..5131b8af 100644 --- a/src/common/fmt.c +++ b/src/common/fmt.c @@ -183,7 +183,7 @@ void bestfta_p(var_num_t x, char *dest, var_num_t minx, var_num_t maxx) { } fpart = fround(frac(x), precision) * pow(10, precision); - if (fpart >= FMT_xRND) { // rounding bug + if (fpart >= pow(10, precision)) { // rounding bug, i.e: print 32.99999999999999 -> Output: 32.1 ipart = ipart + 1.0; if (ipart >= maxx) { ipart = ipart / 10.0; From 1128c5ff8ad41dd9458014b6fa3179b036b59217 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen Date: Sun, 14 May 2023 16:20:41 +0200 Subject: [PATCH 2/2] Fix bug: LINEQN tolerance --- src/common/blib_math.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/blib_math.c b/src/common/blib_math.c index 5c2ba7c1..20e3089c 100644 --- a/src/common/blib_math.c +++ b/src/common/blib_math.c @@ -121,7 +121,7 @@ void mat_gauss_jordan(var_num_t *a, var_num_t *b, int n, double toler) { indxr[i] = irow; indxc[i] = icol; - if (a[icol * n + icol] < toler) { + if (fabs(a[icol * n + icol]) < toler) { err_matsig(); free(indxc); free(indxr);