[cfp-interest 3718] C2Y and signaling NaNs

Jerome Coonen jcoonen at gmail.com
Mon Nov 10 20:54:44 PST 2025


This note addresses this 15 Oct action item carried over to 29 Oct:

Follow up on cfp3618 to see whether snan issues apply to more than signbit,
and what to do about it.

(1) First, let's look at Damian's suggestion in cfp3618 to clarify F.3p7:

         ...This applies to all values, including <<<both quiet and
signaling>>> NaNs<<<,>>> whose sign bit is not generally interpreted by
ISO/IEC 60559.

The angle brackets denote changes.The added comma clarifies that the
following phrase is informational, applying to all NaNs.

The mention of "both quiet and signaling" NaNs is arguable. F.2.2p2, quoted
below, states that "NaN" refers to a quiet NaN unless stated otherwise. In
this case, both flavors of NaN are intended. However, the next sentence of
F.2.2p2 goes on to specify what to do with signaling NaNs, which addresses
the signbit macro at hand. Are the extra words really needed?

In our meetings, we generally agree to avoid unneeded explanations, which
can leave a reader wondering, "Why aren't signaling NaNs called out here,
if they were called out there?" In this case (and after reviewing the
hundreds of occurrences of "NaN" for context), it seems friendly to add the
explanatory words.

(2) The copysign functions are another set of sign operations of interest.
Section 7.12.12.1 specifies behavior consistent with 60559, with F.2.2p3
once again resolving the behavior with signaling NaNs. F.10.9.1 further
specifies that there be no errors, also consistent with 60559.

(3)The fabs functions are similar in spirit to copysign.

My conclusion is that C2Y handles NaNs unambiguously for all
implementations and consistently with 60559 when that is relevant. The
proposed changes relative to cfp3618 will be an improvement.

-Jerome Coonen

---------------------------------------------------------
READER'S GUIDE of relevant excerpts on signaling NaNs from draft n3685.
Please refer to 6.3 "The sign bit" in 60559 for some perspective from the
point of view from the floating point standard.

5.3.5.3.3p10-11  -- Characteristics of floating types (a subclause referred
to many times)

... a signaling NaN generally raises a floating-point exception when
occurring as an arithmetic operand.


NOTE 2 ISO/IEC 60559 specifies quiet and signaling NaNs. For
implementations that do not support ISO/IEC 60559, the terms quiet NaN and
signaling NaN are intended to apply to values with similar behavior.


7.12.2p3 -- Treatment of error conditions, domain error paragraph

...Whether a signaling NaN input causes a domain error is
implementation-defined. ...


7.12.4 Classification macros:

fpclassify
iscanonical
isfinite
isinf
isnan
isnormal
signbit
issignaling
issubnormal
iszero


7.12.4.9p3 -- The issignaling macro

The issignaling macro returns a nonzero value if and only if its argument
is a signaling NaN.282)


7.12.4.9 footnote 282

282) F.3 specifies that issignaling (and all the other classification
macros), raise no floating-point exception if the argument is a variable,
or any other expression whose value is represented in the format of its
semantic type, even if the value is a signaling NaN.


7.12.12 Manipulation functions:

copysign


7.12.18.2p2 (and several similar comparison cases which raise "invalid"
only if they have an snan operand)

...However, unlike (x) > (y), isgreater(x,y) does not raise the "invalid"
floating-point exception when x and y are unordered and neither is a
signaling NaN.


F2.2p3 -- Infinities and NaNs

This annex does not require the full support for signaling NaNs specified
in ISO/IEC 60559. This annex uses the term NaN, unless explicitly
qualified, to denote quiet NaNs. Where specification of signaling NaNs is
not provided, the behavior of signaling NaNs is implementation-defined
(either treated as an ISO/IEC 60559 quiet NaN or treated as an ISO/IEC
60559 signaling NaN).436)


F.2.2p5-7

To support signaling NaNs as specified in ISO/IEC 60559, an implementation
should adhere to the following recommended practice.

Recommended practice

Any floating-point operator or <math.h> function or macro with a signaling
NaN input, unless explicitly specified otherwise, raises an "invalid"
floating-point exception.

NOTE Some functions do not propagate quiet NaN arguments. For example,
hypot(x, y) returns infinity if x or y is infinite and the other is a quiet
NaN. The recommended practice in this subclause specifies that such
functions (and others) raise the "invalid" floating-point exception if an
argument is a signaling NaN, which also implies they return a quiet NaN in
these cases.

F.3p5-7 Operations

The unary + and - operators raise no floating-point exceptions, even if the
operand is a signaling NaN.

The C classification macros fpclassify, iscanonical, isfinite, isinf,
isnan, isnormal, issignaling, issubnormal, iszero, and signbit provide the
ISO/IEC 60559 operations indicated in Table F.2 provided their arguments
are in the format of their semantic type. Then these macros raise no
floating-point exceptions, even if an argument is a signaling NaN.

The signbit macro, providing the ISO/IEC 60559 isSignMinus operation,
determines the sign of its argument value as the sign bit of the value’s
representation. This applies to all values, including NaNs whose sign bit
is not generally interpreted by ISO/IEC 60559.


F.10.5.3p2 The fabs functions

fabs(x) raises no floating-point exceptions, even if x is a signaling NaN.

F.10.9.1p1 The copysign functions

copysign(x, y) raises no floating-point exceptions, even if x or y is a
signaling NaN. The returned value is independent of the current rounding
direction mode.

-----------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20251110/9f91c58a/attachment-0001.htm>


More information about the cfp-interest mailing list