bug-gnu-emacs
[Top][All Lists]
Advanced

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

NaN and equal


From: James Clark
Subject: NaN and equal
Date: Wed, 13 Aug 2003 08:24:10 +0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225

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





reply via email to

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