https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128383
Bug ID: 128383
Summary: fixed on real gives wrong digits
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: algol68
Assignee: algol68 at gcc dot gnu.org
Reporter: stefan.zobel at gmail dot com
Target Milestone: ---
begin
puts (fixed (1.6e7, 0, 1) + "'n");
puts (fixed (123456.0, 0, 2) + "'n")
end
ga68 | expected
fixed (1.6e7, 0, 1) | 15999999.0 | 16000000.0
fixed (123456.0, 0, 2) | 123456.01 | 123456.00
Both values are exact in a 32-bit real. subfixed (line 306) follows
the algorithm of the Revised Report, which assumes exact arithmetic:
- it first adds the rounding term .5 * .1 ** after;
- it divides by 10.0 ** before;
- then it takes the digits one by one with y *:= 10.0 and y -:= c.
With a 24-bit significand this goes wrong in two ways:
- The rounding term is rounded itself: 123456.0 + 0.005 becomes
123456.0078125, the next float, which then rounds to .01.
- The scaling is inexact: 16000000.0 / 10.0 ** 8 is a little below
0.16, so every digit after the first comes out as 9.