delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/03/27/04:51:31

From: Martin Stromberg <Martin DOT Stromberg AT lu DOT erisoft DOT se>
Date: Mon, 27 Mar 2000 10:11:43 +0200 (MET DST)
Message-Id: <200003270811.KAA29766@lws256.lu.erisoft.se>
To: djgpp-workers AT delorie DOT com
Subject: (fwd) Re: "[-]nan" in C99
Newsgroups: comp.std.c
Reply-To: djgpp-workers AT delorie DOT com

Yet another:
From: "Fred Tydeman" <tydeman AT tybor DOT com>

Martin Stromberg wrote in message <8ba9j6$f1k$1 AT antares DOT lu DOT erisoft DOT se>...
>So supposing that X is a NaN, whatever NaN, with the sign bit set,
>should printf("%Lf\n", X) print "-nan" or only "nan"?


It should print "-nan".

>Must printf("%Lf\n", X) print "-nan?


The intent (from those of us on the j11 committee most concerned with adding
support for IEEE-754 to C) is yes, but I do not yet find the words in the
C99
Standard to require it.

7.19.6.1 The fprintf function:  subsection on "f, F":  "A double argument
representing a NaN is converted in one of the styles [-]nan or
[-]nan(n-char-sequence)
-- which style, and the meaning of any n-char-sequence, is
implementation-defined."

The C Standard clearly shows that NaNs can and may be printed with a
negative sign.

Other points raised on this discussion:

There is a difference between IEEE-754 (which came first) and IEEE-854
(since it came second, one could assume they got the wording better) on
the sign bit and NaNs:

  IEEE-754: 6.3 The Sign Bit:
    "This standard does not interpret the sign of an NaN."
  IEEE-854: 6.3 The Algebraic Sign:
    "The sign of a NaN is not determined by this standard."

So, the following:
  +0 / +0 => +NAN    same for +INF / +INF
  +0 / -0 => -NAN    same for +INF / -INF
  -0 / +0 => -NAN    same for -INF / +INF
  -0 / -0 => +NAN    same for -INF / -INF
is not required, but is allowed.

Both 754 and 854 say that copysign and -x may be treated as nonarithmetic
operations which do not need to raise invalid for signaling NaNs.  Hence, -x
can be done as an integer exclusive OR bit operation to just flip the sign
bit
(rather than as a floating-point arithmetic operation).

IEEE-754 and 854 differ on printing NaNs:
  IEEE-754: 5.6 Binary <-> Decimal Conversion:
    "Over/underflow and NaNs and infinitied encountered during binary
    to decimal conversion should be indicated to the user by
    appropriate strings.  NaNs encoded in decimal strings are not
    specified by this standard."
 IEEE-854: 5.6 Floating-Point <-> Decimal String Conversion:
    "Overflow/underflow and NaNs and infinities encountered during
    floating-point to decimal string conversion should be indicated to
    the user by appropriate strings.  The letters "NaN," case
    insensitive, optionally preceded by an algebraic sign, should
    be the first characters of a string representing a NaN."

IEEE-854 added some new text (as compared to IEEE-754):
3.1 Sets of Values: "An implementation may find it helpful to
provide additional information about a variable that is NaN
through an algebraic sign, but this standard does not
interpret such extensions."




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019