emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting NaN to integer 0.


From: Paul Eggert
Subject: Re: Converting NaN to integer 0.
Date: Tue, 12 Feb 2002 13:43:42 -0800 (PST)

> From: Richard Stallman <address@hidden>
> Date: Tue, 12 Feb 2002 08:24:43 -0700 (MST)
> 
> Does anyone know what is the "correct" thing to do in this case
> according to IEEE?

ANSI/IEEE Std 754-1985 section 7.1 says:

  The invalid operation exception is signaled if an operand is invalid
  for the operation to be performed.  The result, when the exception
  occurs without a trap, shall be a quiet NaN (6.2) provided the
  destination has a floating-point format.  The invalid operations are
  ...

    (7) Conversion of a binary floating-point number to an integer or
    decimal format when overflow, infinity, or NaN precludes a
    faithful representation in that format and this cannot otherwise
    be signaled

> Would returning NaN be correct?

Yes, if you decide that the destination format is a Lisp object, since
a Lisp object can faithfully represent NaN.  Similarly, it would be
correct to return +-infinity for infinities and for floating-point
numbers that are too large to represent in the destination integer
format.

However, if you decide that the destination format must be an integer
Lisp object (i.e. that it cannot be a floating-point Lisp object),
then the ANSI/IEEE 754 is silent about what integer is returned for
NaNs, infinities, and out-of-range floating-point numbers.

The ISO C 99 standard agrees with ANSI/IEEE 754 here.  It says that on
a host that uses IEEE floating point, when a NaN or out-of-range value
is converted to an (necessarily fixed-width) integer, the invalid
operation exception is raised and the resulting integer value is
unspecified.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]