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. > This option is not turned on by any @option{-O} option since > it can result in incorrect output for programs that depend on > -- > ────────────────────────────────────────────────────────────────────────── > Dr. Matthias Kretz https://mattkretz.github.io > GSI Helmholtz Centre for Heavy Ion Research https://gsi.de > std::experimental::simd https://github.com/VcDevel/std-simd > ────────────────────────────────────────────────────────────────────────── >