[Patch, Fortran] PR34333 - Handle parameter NAN properly in MAX, MIN, == etc.

Tobias Burnus burnus@net-b.de
Tue Dec 4 20:44:00 GMT 2007

:ADDPATCH fortran:

The program (to be compiled with -fno-range-check)

real, parameter :: nan = 0.0/0.0
if (nan == nan) call abort()
print *, max(nan, 4.0) ! shall print "4.0"

should not abort as  (nan /= nan) shall evaluate as true. This patch
ensures that comparisons and MIN/MAX work properly for NaN, by using
mpfr_min and mpfr_max instead of home-grown mpfr_cmp/mpfr_set solutions.

It additionally replaces mpfr_cmp by mpfr_equal_p etc. which take NaN
into account. I had to pass the wanted argument to gfc_compare_expr to
ensure that for  "nan > nan", "nan < nan" and "nan == nan" the result is
always false.

Build and regression tested on x86-64-linux.
OK for the trunk?


PS: I essentially copied the test case nan_1.f90 and changed the
variables to parameters.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nan2.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20071204/baf038c2/attachment.ksh>

More information about the Gcc-patches mailing list