From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Q on NaN Date: Fri, 24 Jun 2005 23:01:07 +0200 Message-ID: References: Reply-To: Eli Zaretskii NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1119643368 13587 80.91.229.2 (24 Jun 2005 20:02:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2005 20:02:48 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 24 22:02:45 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DluNX-0000OT-Oq for ged-emacs-devel@m.gmane.org; Fri, 24 Jun 2005 22:02:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DluUd-0001pV-Hg for ged-emacs-devel@m.gmane.org; Fri, 24 Jun 2005 16:09:39 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DluQe-00012p-GA for emacs-devel@gnu.org; Fri, 24 Jun 2005 16:05:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DluQG-0000q2-5X for emacs-devel@gnu.org; Fri, 24 Jun 2005 16:05:13 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DluQE-0000pC-Bd for emacs-devel@gnu.org; Fri, 24 Jun 2005 16:05:06 -0400 Original-Received: from [192.114.186.24] (helo=legolas.inter.net.il) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DluQ2-0007oc-I2 for emacs-devel@gnu.org; Fri, 24 Jun 2005 16:04:54 -0400 Original-Received: from HOME-C4E4A596F7 (IGLD-80-230-156-159.inter.net.il [80.230.156.159]) by legolas.inter.net.il (MOS 3.5.8-GR) with ESMTP id ESE09864 (AUTH halo1); Fri, 24 Jun 2005 23:01:09 +0300 (IDT) Original-To: "Drew Adams" In-reply-to: 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:39451 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:39451 > From: "Drew Adams" > Date: Fri, 24 Jun 2005 12:33:53 -0700 > > (condition-case nil (setq foo (/ 0.0 0.0)) (arith-error nil)) > In older versions of Emacs (at least prior to April 2005 CVS), > this would evaluate to nil. Now, it evaluates to -0.0NaN. > I can modify the code like so: > (and (condition-case nil (setq foo (/ 0.0 0.0)) (arith-error nil)) > (bar foo)) ; foo must be a number, not a NaN > What function do I use for bar? > `numberp' doesn't work, since (numberp -0.0NaN) is non-nil. > > To make the point simpler: > > (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. 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.