[Gambas-bugtracker] Bug #1562: Bad calculation

bugtracker at gambaswiki.org bugtracker at gambaswiki.org
Thu Apr 18 21:47:26 CEST 2019


http://gambaswiki.org/bugtracker/edit?object=BUG.1562&from=L21haW4-

Comment #2 by juan JUAN:

Is not the same

Print acos (-1) - acos (-1 + 1e-16)

what

a = a + 1e-16
print a, ACos (a)

because in the second line I obtain that a = 1 and ACos(a) differs a lot from ACos(1), as well as that only 8 decimal digits of precision are obtained. Within a more extensive program, the first line may occur in a very different place from where the second occurs and even not be so obvious (for example, there is no line a = a + 1e-16 but the result is produced by rounding in intermediate calculations). And it is not the same Print a, ACos (a) ==> 1.0000000000000001, 3.14159263868863 (which does give a clue of what is happening) that Print a, ACos (a) ==> 1, 3.14159263868863 (which is puzzling in a scenario like the one described).

And I am not criticizing anything but making evident a situation that can cause frustration. It can (can only) be worth evaluating the rounding criteria near zero. Another flagrant case:

if (a = 0) then
     b = 1
else
     b = 1 / a
end if

Again, if a = 1e-16 (not necessarily explicitly), b = 1e16 is obtained, which can eventually provide a highly undesirable result. And neither Print nor the debugger give clues of what happens.

Regards




More information about the Bugtracker mailing list