This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[gfortran,patch] Make MIN and MAX handle NaNs correctly (PR32048)
- From: FX Coudert <fxcoudert at gmail dot com>
- To: gfortran list <fortran at gcc dot gnu dot org>
- Cc: gcc-patches list <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 28 Jul 2007 15:47:54 +0100
- Subject: [gfortran,patch] Make MIN and MAX handle NaNs correctly (PR32048)
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:mime-version:to:message-id:content-type:cc:subject:from:date:x-mailer; b=tBm+GcU5faul4UnDubcBi1Ic7+fsWpBXkKaC5Jpvzevxa+HoLhgFCQ6yL8PKDB68sSA+BzkXofaq1Gb78nbINfmASTq3P5ssX/dnNIVGl6+HYTMFReBJGNkvSmrcxMXoSt6hj4EnaZUIzhJe8fNze1FC9/Potz9mDEjZbSy57/E=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:mime-version:to:message-id:content-type:cc:subject:from:date:x-mailer; b=OTyvLx4Ormsfy/CRcu/+XAB5YJxIN7qnHZYRg4FZjlQppu9HwG2WL3IizZxNJW0dJhcS3zOWb0OZmSYWKwbPe58wnpas0/KsaEeHpoxI6U9010WkEIKLU7HoW0b+zwSXuEvj5yWW7WEgOnt59ncbYoP9ZQxzxbJ4swS3Od4weZg=
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:
Attachment:
minmax_nan.ChangeLog
Description: Binary data
Attachment:
minmax_nan.diff
Description: Binary data