maxval on -inf and nan in Fortran

Tobias Burnus tobias@codesourcery.com
Fri Feb 28 15:11:00 GMT 2020


On 2/28/20 3:53 PM, Segher Boessenkool wrote:
> It happens with -O2 already. The frontend generates a MIN_EXPR (or
> MAX_EXPR) for this, which is undefined for NaNs already. I think the
> testcase is just invalid?

Ups, that shouldn't happen. It does seem to work here
(x86-64-gnu-linux), however, running various compile flags including -O3
and -O2.

Regarding MIN and MAX: I think the IEEE 754 decided at some point
decided that MAX(x, NaN) = x (IEEE 754:2008 alias ISO 60559:2011, if I
recall correctly). I think one has to check what exactly the test case
does and what is guaranteed where. I also do not know whether a more
recent IEEE 754 (754:2019) has changed something again.

The Fortran standard by itself does not know about NaN; however, things
do change if an intrinsic IEEE_* module is loaded – I don't quickly
which one needs to be loaded and which part has to be checked there.

I think in terms of NaN/INF and MAX/MIN, the normal MAX/MIN remain the
same (nothing said about nonnormal numbers except 0), but IEEE_MAX_NUM
does take care of the IEEE 754 semantic.

Tobias

PS: I currently do not have the time dig into this; maybe on Monday or
at the weekend.

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter



More information about the Gcc-patches mailing list