This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH/gfortran] Fix rounding in constant folding
Tobias Schlüter wrote:
> Steve Kargl wrote:
>
>>>In order of increasing probability: Does mpfr round incorrectly? Do we do
>>>something wrong? Or am I being stupid?
>
>
> Further investigation proved the last of these options to be the case.
Hm, upon looking at this again, this is not the case, and therefore is the
case again. The important conclusion is that our implementation of NEAREST is
wrong:
[tobi@marktplatz tests]$ cat prec.f90
print *, 0.49999997, nint (0.49999997)
print *, nearest (0.5, -1.), nint(nearest (0.5, -1.))
x = 0.5
print *, nearest (x, -1.), nint(nearest(x,-1.))
end
gives the following output:
0.5000000 1
0.4999999 0
0.5000000 0
So the result for NEAREST as evaluated by the constant folders is too small.
It looks like mpfr provides what is needed, so I'll cook up a patch.
- Tobi