* NaN and equal
@ 2003-08-13 1:24 James Clark
0 siblings, 0 replies; only message in thread
From: James Clark @ 2003-08-13 1:24 UTC (permalink / raw)
With Emacs 21.3.1, i686-pc-linux-gnu
(equal 0.0e+NaN 0.0e+NaN)
returns nil. This does not seem consistent with the documentation of
equal. I would suggest that (= 0.0e+NaN 0.0e+NaN) continues to return
nil, for consistency with the IEEE floating point standard (which of
course says that NaN != NaN), but that (equal 0.0e+NaN 0.0e+NaN) return
t, so that hash-tables and alists with NaN can work.
Here's a patch. I don't think this should cause any problems on systems
without NaN.
*** /home/jjc/var/build/emacs-21.3/src/fns.c~ 2002-12-04
19:38:32.000000000 +0700
--- /home/jjc/var/build/emacs-21.3/src/fns.c 2003-08-12
23:04:52.000000000 +0700
***************
*** 1976,1982 ****
switch (XTYPE (o1))
{
case Lisp_Float:
! return (extract_float (o1) == extract_float (o2));
case Lisp_Cons:
if (!internal_equal (XCAR (o1), XCAR (o2), depth + 1))
--- 1976,1990 ----
switch (XTYPE (o1))
{
case Lisp_Float:
! {
! double d1, d2;
!
! d1 = extract_float (o1);
! d2 = extract_float (o2);
! /* If d is NaN, then d != d. Two NaNs should be equal
! even though they are not =. */
! return d1 == d2 || (d1 != d1 && d2 != d2);
! }
case Lisp_Cons:
if (!internal_equal (XCAR (o1), XCAR (o2), depth + 1))
James
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-08-13 1:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-13 1:24 NaN and equal James Clark
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).