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 14:49:04 -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 1119650838 1211 80.91.229.2 (24 Jun 2005 22:07:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2005 22:07:18 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 25 00:07:16 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DlwDj-0007ub-I8 for ged-emacs-devel@m.gmane.org; Sat, 25 Jun 2005 00:00:19 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DlwKq-0007Iq-7U for ged-emacs-devel@m.gmane.org; Fri, 24 Jun 2005 18:07:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DlwGX-0004nz-M1 for emacs-devel@gnu.org; Fri, 24 Jun 2005 18:03:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DlwF9-0004Na-DL for emacs-devel@gnu.org; Fri, 24 Jun 2005 18:01:55 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DlwF4-0004JZ-CJ for emacs-devel@gnu.org; Fri, 24 Jun 2005 18:01:42 -0400 Original-Received: from [141.146.126.229] (helo=agminet02.oracle.com) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1Dlw6X-00079f-UN for emacs-devel@gnu.org; Fri, 24 Jun 2005 17:52:54 -0400 Original-Received: from agminet02.oracle.com (localhost [127.0.0.1]) by agminet02.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id j5OLn9S2022551 for ; Fri, 24 Jun 2005 16:49:09 -0500 Original-Received: from rgmsgw300.us.oracle.com (rgmsgw300.us.oracle.com [138.1.186.49]) by agminet02.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id j5OLn8Qo022530 for ; Fri, 24 Jun 2005 16:49:08 -0500 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 j5OLn7Rf013690 for ; Fri, 24 Jun 2005 15:49:07 -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 j5OLn6mD013683 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Fri, 24 Jun 2005 15:49:07 -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:39461 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:39461 > I didn't say above that (/0.0 0.0) should give `arith-error'. Well, you seemed to: you complained that it did so in previous versions. No, I said "fair enough" to that change in behavior. I did not suggest it was a bug. My question was about numberp's behavior: > 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? Any floating-point value is a ``number'' as far as `numberp' is concerned. The fact that NaN is a short for not-a-number does not mean that Lisp should treat it like that. I can see that from the behavior, but then perhaps it should be mentioned explicitly in the doc. Since the names suggest something different, perhaps a note of clarification should be added. > 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. Exactly the same: (= foobar foobar). (Did you try that?) Right. Got it; thanks. A couple of people replied with the same solution. I am using (equal 0.0e+Nan), which also seems to work (and if equivalent, would perhaps be clearer, since it mentions NaN: anything equal to NaN is NaN). Does anyone know that these are not equivalent: (equal 0.0e+NaN) <=?=> (and (numberp x) (/= x x)) That is, are there any objects equal to 0.0e+NaN that are not NaN? It might also be useful to mention such an idiom - either expression - in the doc, or else to provide a predicate. > 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. No need: the arithmetic equality trick takes care of all of the possible values. Right. All NaNs are `equal', but they are not `=', even to themselves. Note that you should use `=', not `equal' (nor `eql', btw). Yes, for testing a numberp to see if it is not NaN. However, I am testing an arbitrary object. For that, (and (numberp x) (/= x x)) works and (equal x 0.0e+Nan) works. For the latter test, it must be `equal' or `eql', not `=' or `eq'.