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: Elisp manual, node "Comparison of Numbers" Date: Mon, 29 May 2006 06:20:20 -0700 Message-ID: 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 1148908938 24524 80.91.229.2 (29 May 2006 13:22:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 29 May 2006 13:22:18 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 29 15:22:15 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Fkhgh-0004N5-5k for ged-emacs-devel@m.gmane.org; Mon, 29 May 2006 15:21:39 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fkhgd-0000Ce-Le for ged-emacs-devel@m.gmane.org; Mon, 29 May 2006 09:21:35 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FkhgR-0000CE-Em for emacs-devel@gnu.org; Mon, 29 May 2006 09:21:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FkhgN-0000Bj-RD for emacs-devel@gnu.org; Mon, 29 May 2006 09:21:22 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FkhgN-0000Bg-Ib for emacs-devel@gnu.org; Mon, 29 May 2006 09:21:19 -0400 Original-Received: from [199.232.41.67] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Fkhls-0001z2-1s for emacs-devel@gnu.org; Mon, 29 May 2006 09:27:00 -0400 Original-Received: from [148.87.113.118] (helo=rgminet01.oracle.com) by mx20.gnu.org with esmtp (Exim 4.52) id 1Fkhfd-00020x-Hz for emacs-devel@gnu.org; Mon, 29 May 2006 09:20:33 -0400 Original-Received: from rgmsgw301.us.oracle.com (rgmsgw301.us.oracle.com [138.1.186.50]) by rgminet01.oracle.com (Switch-3.1.6/Switch-3.1.6) with ESMTP id k4TDKVWg025194 for ; Mon, 29 May 2006 07:20:31 -0600 Original-Received: from dradamslap (dhcp-amer-whq-csvpn-gw3-141-144-81-124.vpn.oracle.com [141.144.81.124]) by rgmsgw301.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with SMTP id k4TDKTLq032612 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Mon, 29 May 2006 07:20:30 -0600 Original-To: "Emacs-Devel" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE 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:55424 Archived-At: I blindly got bit by this one. The Elisp manual gives this as an example of how to test near equality of floating-point numbers: (defvar fuzz-factor 1.0e-6) (defun approx-equal (x y) (or (and (= x 0) (= y 0)) (< (/ (abs (- x y)) (max (abs x) (abs y))) fuzz-factor))) When either x or y is 0.0, but not both, this gives nil no matter how close the other number is to zero. I think this is more like what is needed: (defun approx-equal (x y &optional fuzz) (setq fuzz (or fuzz 1.0e-8)) (cond ((= x 0.0) (< y fuzz)) ((= y 0.0) (< x fuzz)) (t (< (/ (abs (- x y)) (max (abs x) (abs y))) fuzz))))