From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: Q on NaN Date: Fri, 24 Jun 2005 13:26:23 -0700 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1119645023 19239 80.91.229.2 (24 Jun 2005 20:30:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2005 20:30:23 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 24 22:30:19 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DluoE-0006i2-Aq for ged-emacs-devel@m.gmane.org; Fri, 24 Jun 2005 22:29:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DluqY-0001DA-7Y for ged-emacs-devel@m.gmane.org; Fri, 24 Jun 2005 16:32:18 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Dluq0-00017f-T8 for emacs-devel@gnu.org; Fri, 24 Jun 2005 16:31:45 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Dlupx-00015j-10 for emacs-devel@gnu.org; Fri, 24 Jun 2005 16:31:42 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dlupv-0000yD-HP for emacs-devel@gnu.org; Fri, 24 Jun 2005 16:31:40 -0400 Original-Received: from [148.87.122.33] (helo=rgminet04.oracle.com) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1DluoW-0001FF-Kf for emacs-devel@gnu.org; Fri, 24 Jun 2005 16:30:12 -0400 Original-Received: from rgminet04.oracle.com (localhost [127.0.0.1]) by rgminet04.oracle.com (Switch-3.1.6/Switch-3.1.6) with ESMTP id j5OKQS4p021431 for ; Fri, 24 Jun 2005 14:26:28 -0600 Original-Received: from rgmsgw300.us.oracle.com (rgmsgw300.us.oracle.com [138.1.186.49]) by rgminet04.oracle.com (Switch-3.1.6/Switch-3.1.6) with ESMTP id j5OKQQad021388 for ; Fri, 24 Jun 2005 14:26:27 -0600 Original-Received: from rgmsgw300.us.oracle.com (localhost [127.0.0.1]) by rgmsgw300.us.oracle.com (Switch-3.1.4/Switch-3.1.0) with ESMTP id j5OKQQeo010232 for ; Fri, 24 Jun 2005 14:26:26 -0600 Original-Received: from dradamslap (dhcp-amer-whq-csvpn-gw3-141-144-80-138.vpn.oracle.com [141.144.80.138]) by rgmsgw300.us.oracle.com (Switch-3.1.4/Switch-3.1.0) with SMTP id j5OKQPs5010216 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Fri, 24 Jun 2005 14:26:26 -0600 Original-To: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 Importance: Normal X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:39454 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:39454 > (numberp (/0.0 0.0)) returns t. That seems like a bug to me. Maybe it is, maybe it isn't. (elisp)Arithmetic Operations says: If you divide an integer by 0, an `arith-error' error is signaled. (*Note Errors::.) Floating point division by zero returns either infinity or a NaN if your machine supports IEEE floating point; otherwise, it signals an `arith-error' error. So if the machine supports IEEE floating point (most modern machines do), you aren't supposed to get `arith-error' in this case. Maybe this is a bit counter-intuitive for someone who never did futz with NaNs, but at least Emacs behaves consistently with the docs. I didn't say above that (/0.0 0.0) should give `arith-error'. I suggested that perhaps `numberp' should return nil for a NaN argument, since "NaN" means "not a number" and "numberp" means "a number". NaN is a floating-point value, but is it a number? As for a way to test for a NaN, try this: (= (/ 0.0 0.0) (/ 0.0 0.0)) It should evaluate to nil, since a NaN is defined to fail _any_ arithmetic comparison, even a comparison to itself. That doesn't tell me how to test if `foobar' is a NaN. See my previous email: I knew I could test `(equal foo 0.0e+Nan)', but I thought I would need to test against all of the possible NaN values. A bit of experimenting shows, however, that, at least on my system, the mantissa doesn't matter: (equal 0.0e+NaN -0.0e+NaN) is `t', as is (equal 1.0e+NaN -99.5e+NaN). There is effectively only a single NaN value. So I guess the answer to my original question is this: (and (condition-case nil (setq foo (/ 0.0 0.0)) (arith-error nil)) (not (equal 0.0e+NaN foo))) Ugly, perhaps, but usable. BTW, here is something I didn't expect: `M-: 0.0e+NaN' returns -0.0e+NaN `M-: -0.0e+NaN' returns 0.0e+NaN The reader seems to flip the (irrelevant) sign.