[Cfp-interest 3230] Re: Can nan() set errno?

Joshua Cranmer joshua.cranmer at intel.com
Mon Aug 19 10:10:51 PDT 2024


On 8/18/2024 18:19, Fred J. Tydeman wrote:
> OK for the return value.
> But, is an implementation allowed to indicate an error
> (either via errno or the FP exception flags)?

The interpretation I gave when asked this question a few weeks ago was this:

|strotod| says for NaN sequences:

    A character sequence |NAN| or |NAN(n-char-sequenceopt)| is
    interpreted as a quiet NaN, if supported in the return type, else
    like a subject sequence part that does not have the expected form;
    the meaning of the n-char sequence
    is implementation-defined.

It gives explicit rules for overflow and underflow, which can set 
|errno| values, but is silent on what happens with the n-char sequence 
being out of range of the payload, outside of the above quote. But... 
there's not really any latitude I see in the specification for |errno| 
to be set (unless you think 7.12.1 applies to |nan| and sNaN is a domain 
error).

glibc fails because it's using |strtoull| here, and |strtoull| does 
|ERANGE| on overflow. But I think this is a glibc bug, it shouldn't be 
setting errno. [This bug was filed as 
https://sourceware.org/bugzilla/show_bug.cgi?id=32045, there's been no 
discussion on the bug yet.]


If this interpretation is correct, it wouldn't be a bad idea to add a 
note saying that strtod converting to nans or the nan function can't 
return errno; if it's not correct, then normative text should be added 
to cover the errno case.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20240819/b4a7c48e/attachment-0001.htm>


More information about the Cfp-interest mailing list