unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@twinsun.com>
Cc: emacs-devel@gnu.org
Subject: Re: Converting NaN to integer 0.
Date: Tue, 12 Feb 2002 13:43:42 -0800 (PST)	[thread overview]
Message-ID: <200202122143.g1CLhgq11763@shade.twinsun.com> (raw)
In-Reply-To: <200202121524.g1CFOhK07421@aztec.santafe.edu> (rms@gnu.org)

> From: Richard Stallman <rms@gnu.org>
> 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.

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel


  parent reply	other threads:[~2002-02-12 21:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200202110253.g1B2r5E10557@swt40.swt.com>
2002-02-12 15:24 ` Converting NaN to integer 0 Richard Stallman
2002-02-12 16:46   ` Luc Teirlinck
2002-02-12 21:43   ` Paul Eggert [this message]
2002-02-12 23:46   ` Luc Teirlinck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200202122143.g1CLhgq11763@shade.twinsun.com \
    --to=eggert@twinsun.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).