The existing code was poorly formatted (incorrect indendation) and very messy (reusing the variable name l for several different things). So I reformatted it and changed some variable names to understand it better before applying my patch. It can certainly be cleaned up further, but my main goal was to fix this bug.
Please read and try out the code and let me know what you think.
It looks like this bug was actually fixed by Ray Toy a while ago (commit d1976ae dated 2021-09-24). I don't see the buggy behavior with a current build.
Version 5.45.1 is dated 2021-06-20 so it doesn't include the bug fix.
I think it's still meaningful to clean up the code and include new test cases, including any specific ones mentioned here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
and...
(%i1) display2d:false;
(%o1) false
(%i2) fpprintprec:4;
(%o2) 4
(%i3) string(9.9999e0);
(%o3) "10.0" <- correct
(%i4) string(9.9999b0);
(%o4) "1.0b0" <- not correct
(%i5) printf(false, "~h", 9.9999b0);
(%o5) "1.0" <- not correct
cf. https://sourceforge.net/p/maxima/bugs/3213/
Another example:
fpprintprec:6$
0.9999999b0 => 1.0b-1 <<<!!! should be 1.0b0.
In fact, you get this incorrect answer for bfloat(1-10^-i) for i in 4..16 and fpprintprec=i-2 or i-1.
Actually, anything from
1-0.5*10^-ito1-5*10^-ihits this bug.Tested on Maxima 5.45.1 SBCL 2.0.0 Windows
Last edit: Stavros Macrakis 2023-01-29
Here is some proposed code to fix
fpformat.The existing code was poorly formatted (incorrect indendation) and very messy (reusing the variable name
lfor several different things). So I reformatted it and changed some variable names to understand it better before applying my patch. It can certainly be cleaned up further, but my main goal was to fix this bug.Please read and try out the code and let me know what you think.
It looks like this bug was actually fixed by Ray Toy a while ago (commit d1976ae dated 2021-09-24). I don't see the buggy behavior with a current build.
Version 5.45.1 is dated 2021-06-20 so it doesn't include the bug fix.
I think it's still meaningful to clean up the code and include new test cases, including any specific ones mentioned here.
Huh. I don't remember doing that at all. And here's a link to the commit [d1976a], just to make it easier to see.
Related
Commit: [d1976a]
Closing this ticket as fixed by commit d1976ae. We can continue to work on FPFORMAT but anyway this bug is fixed.