From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: Elisp manual, node "Comparison of Numbers" Date: Mon, 29 May 2006 16:08:45 +0200 Message-ID: <85bqtgditu.fsf@lola.goethe.zz> References: <85fyitc5w4.fsf@lola.goethe.zz> <447AFCFD.6030405@student.lu.se> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1148911777 3160 80.91.229.2 (29 May 2006 14:09:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 29 May 2006 14:09:37 +0000 (UTC) Cc: Emacs-Devel , Drew Adams , "Kim F. Storm" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 29 16:09:32 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 1FkiQw-0006T7-VY for ged-emacs-devel@m.gmane.org; Mon, 29 May 2006 16:09:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FkiQv-0001x8-Pa for ged-emacs-devel@m.gmane.org; Mon, 29 May 2006 10:09:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FkiQk-0001wz-IB for emacs-devel@gnu.org; Mon, 29 May 2006 10:09:14 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FkiQj-0001wm-SV for emacs-devel@gnu.org; Mon, 29 May 2006 10:09:14 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FkiQj-0001wj-Q1 for emacs-devel@gnu.org; Mon, 29 May 2006 10:09:13 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FkiWJ-000658-Sf for emacs-devel@gnu.org; Mon, 29 May 2006 10:14:59 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1FkiQi-0005t5-GP; Mon, 29 May 2006 10:09:12 -0400 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id A30D51C4D3B1; Mon, 29 May 2006 16:08:45 +0200 (CEST) Original-To: Lennart Borgman In-Reply-To: <447AFCFD.6030405@student.lu.se> (Lennart Borgman's message of "Mon, 29 May 2006 15:54:05 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) 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:55429 Archived-At: Lennart Borgman writes: > Kim F. Storm wrote: >> David Kastrup writes: >> >> >>> "Drew Adams" writes: >>> >>> >>>> 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)))) >>>> >>> The problem here is that fuzz is a _relative_ measure of equality, and >>> you employ it as an absolute measure here. I don't think it a good >>> idea at all that 1e-12 and 0.995e-12 are considered different, while >>> 1e-8 and 0.0 are considered equal. >>> >> >> Agree! >> > Hm. It is the relative distance from 0. It is merely the distance from 0, not the "relative distance". -- David Kastrup, Kriemhildstr. 15, 44793 Bochum