You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 withbfloat: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.
The text was updated successfully, but these errors were encountered: