strtod ("nan") returns negative NaN

Achim Gratz Stromeko@nexgo.de
Tue Aug 14 19:44:00 GMT 2018


Corinna Vinschen writes:
> With your patch, strtold looks more correct, but it still prints the
> sign of NaN:
>
>   strtod ("nan", NULL) = nan
>   strtod ("-nan", NULL) = nan
>   strtold ("nan", NULL) = nan
>   strtold ("-nan", NULL) = -nan
>   nan ("") = nan
>
> Question: What's wrong with that?  Wouldn't it be more correct if
> strtod returns -NaN for "-nan" as well?

That's iffy, the treatment of sign bits for NaN is quite different from
the usual arithmetic rules.  A NaN is literally "not a number", i.e. the
computation has left the domain of representable FP numbers, so it
really doesn't have a sign.  That doesn't stop folks from using the sign
bit on its representation, but that's a different story.  The sign
properly belong to what is called the "payload", which is usally
ignored.  So converting "-nan" (or NaN multiplied by -1) really ought to
be just plain NaN.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf rackAttack:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list