[gfortran,patch] Make MIN and MAX handle NaNs correctly (PR32048)
FX Coudert
fxcoudert@gmail.com
Sat Jul 28 14:48:00 GMT 2007
Attached patch makes MIN and MAX intrinsics return correct IEEE
results (and consistent results) when given one or more NaN as
arguments. It does so by changing the code generated from MAX(a,b) :=
(b > a ? b : a) into MAX(a,b) := (b > a || isnan(a) ? b : a);
handling of multiple arguments is done similarly.
The introduction of isnan() tests probably has a cost, but hey, we
want a correct result anyway, don't we? Thus, I added a note into the
code saying that when IEEE_ARITHMETIC is implemented, we might want
to make this codepath dependent on IEEE_ARITHMETIC being used (I
don't think we should do that, but we should certainly discuss the
option).
I also added a testcase, I don't have much experience with NaNs so I
don't know if all targets have them, does someone know if "x = 0.0 ;
x = x / x;" will result in a NaN in all cases?
Bootstrapped and regtested on x86_64-linux, OK for mainline?
FX
:ADDPATH fortran:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minmax_nan.ChangeLog
Type: application/octet-stream
Size: 344 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070728/8ad1b820/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minmax_nan.diff
Type: application/octet-stream
Size: 6839 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070728/8ad1b820/attachment-0001.obj>
More information about the Fortran
mailing list