Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > On Mon, Apr 27, 2020 at 6:09 PM Matthias Kretz <m.kr...@gsi.de> wrote: >> >> Hi, >> >> This documentation change clarifies the effect of -ffinite-math-only. With >> the >> current documentation, it is unclear what the presence of NaN and Inf >> representations means if (arithmetic) operations on such values are >> unspecified and even classification functions like isnan are unreliable. If >> the hardware thinks a certain bit pattern is a NaN, but the software assumes >> a >> NaN value cannot ever exist, it is questionable whether, from a language >> viewpoint, a representation for NaNs really exists. Because, a NaN is defined >> by its behavior. This change also clarifies that isnan(nan) returning false >> is >> fine. >> >> This relates to PR84949. >> >> * doc/invoke.texi: Clarify the effects of -ffinite-math-only. >> --- >> gcc/doc/invoke.texi | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi >> index a37a2ee9c19..9e76ab057a9 100644 >> --- a/gcc/doc/invoke.texi >> +++ b/gcc/doc/invoke.texi >> @@ -11619,8 +11619,10 @@ The default is @option{-fno-reciprocal-math}. >> >> @item -ffinite-math-only >> @opindex ffinite-math-only >> -Allow optimizations for floating-point arithmetic that assume >> -that arguments and results are not NaNs or +-Infs. >> +Assume that floating-point types in the language do not have representations >> for >> +NaNs and +-Inf. Whether floating-point hardware supports and acts on NaNs >> and >> ++-Inf is not affected. The behavior of a program that uses a NaN or +-Inf >> value >> +as function argument, macro argument, or operand is undefined. > > Minor nit here - I'd avoid the 'undefined' word which has bad connotation > and use 'unspecified'. Maybe we can even use ISO C language specification > terms but I'm not sure which one is most appropriate here. > > Curiously __builtin_nan ("nan") still gets you a NaN representation > but isnan(__builtin_nan("nan")) is resolved to false.
Yeah, for that and other reasons, I think it would be good to avoid giving the impression that -ffinite-math-only can be relied on to make the assumption above. Wouldn't it be more accurate to say that the compiler is allowed to make the assumption, at any point that it seems convenient? Thanks, Richard