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
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sat, 09 Apr 2005 19:31:26 +0200
- Subject: Re: [PATCH/gfortran] Fix rounding in constant folding
- References: <20050409162248.GA22593@troutmask.apl.washington.edu>
Steve Kargl wrote:
> Ok to commit to mainline and 4.0?
>
> 2005-04-09 Steven G. Kargl <kargls@comcast.net>
>
> * simplify.c (gfc_simplify_anint): Use mpfr_round()
> (gfc_simplify_dnint): ditto.
> (gfc_simplify_nint): ditto.
>
This is ok, except:
> 2005-04-09 Steven G. Kargl <kargls@comcast.net>
>
> * gfortran.dg/nint_1.f90: New test.
> * gfortran.dg/anint_1.f90: ditto.
Please add tests for dnint and put all tests into a single testcase. Please
also add tests for negative constants. (I think the higher granularity we
gain by testing everything individuality is more than offset by the additional
time it takes the testsuite to run.)
> program nint_1
> if (nint(8388609.0) /= 8388609) call abort
> if (nint(0.49999997) /= 0) call abort
> end program nint_1
I would argue for calculating these magic numbers from the model numbers, i.e.
use nint (nearest (0.5, -1.)). Unfortunately, my argument fails the real-life
test: nint(nearest(...)) gives the correct result (=zero) with an unpatched
compiler on my box, whereas the literal constant from your example doesn't.
In order of increasing probability: Does mpfr round incorrectly? Do we do
something wrong? Or am I being stupid?
Oh, and 4.0 is Mark's call.
- Tobi