Skip to content

engineering-format prints 1.0e+3 as 100.0e+1 #4175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rtoy opened this issue Jul 10, 2024 · 0 comments
Open

engineering-format prints 1.0e+3 as 100.0e+1 #4175

rtoy opened this issue Jul 10, 2024 · 0 comments

Comments

@rtoy
Copy link
Owner

rtoy commented Jul 10, 2024

Imported from SourceForge on 2024-07-09 19:32:41
Created by macrakis on 2021-05-21 21:47:56
Original: https://sourceforge.net/p/maxima/bugs/3785


The engineering-format package is supposed to force floating exponents to be divisible by 3.
In SBCL, printing 1000.0 using that package gives 100.0e+1, where the correct formatting is 1.0e+3. This is especially egregious since 1000.0 is exactly representable.

The problem is in the engineering-format routine, which makes the incorrect assumption that (floor (/ (log (abs x)) (log 10.0))) calculates the correct exponent. It does not. In particular, the correctly rounded value of (/ (log 1000.0) (log 10.0)) is 2.9999999999999996, as verified with bfloat:100$ float(log(1000.0b0))/float(log(10.0b0))-3 => -4e-16.

You might think that you could fix this by instead calculating (log 1000.0 10.0), but the Common Lisp spec defines this as (/ (log 1000.0) (log 10.0)).

I bet the simplest way to fix this is to parse the results of the regular formatting routine instead of trying to reimplement accurate decimal printing.

This bug was previously reported for ECL (#3445), CCL (#3444), and SBCL (#???), but for some reason those bug reports were closed even though they weren't resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant