Does posix say anything about the sign in NaNs ?

Garrett Wollman wollman at csail.mit.edu
Sat Dec 27 23:00:32 UTC 2014


<<On Fri, 26 Dec 2014 01:00:48 +1100 (EST), Bruce Evans <brde at optusnet.com.au> said:

> On Wed, 24 Dec 2014, Pedro Giffuni wrote:
>> I got the attached patch from OpenBSD.
>> 
>> It says:
>> ____
>> Show the sign for NaN as per POSIX; from Elliott Hughes.
>> ok martynas@, millert@, doug@
>> ____
>> 
>> I can't find a reference in POSIX documentation to support it though.

> The behaviour is implementation-defined.  From n869.txt for printf:

An old draft of the C standard is not necessarily relevant here, since
POSIX may place requirements on implementations beyond those of C.

The 2008 POSIX standard (aka SUSv7) had this to say (XBD7 p. 247,
<float.h>):

	An implementation may give zero and non-numeric values, such
	as infinities and NaNs, a sign, or may leave them
	unsigned. Wherever such values are unsigned, any requirement
	in POSIX.1-2008 to retrieve the sign shall produce an
	unspecified sign and any requirement to set the sign shall be
	ignored.

I haven't checked the current edition to see whether it differs in
this regard, but I doubt it.

XSH7 page 932 (fscanf()) additionally requires:

	If the fprintf ( ) family of functions generates character
	string representations for infinity and NaN (a symbolic entity
	encoded in floating-point format) to support IEEE Std
	754-1985, the fscanf ( ) family of functions shall recognize
	them as input.

My view would be that FreeBSD is free to determine that NaN is an
unsigned value, and no conforming application can distinguish signed
NaNs (either positive or negative) from unsigned NaNs.

-GAWollman


More information about the freebsd-standards mailing list