From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: Elisp manual, node "Comparison of Numbers" Date: Mon, 29 May 2006 23:46:59 -0400 Message-ID: References: Reply-To: rms@gnu.org NNTP-Posting-Host: main.gmane.org Content-Type: text/plain; charset=ISO-8859-15 X-Trace: sea.gmane.org 1148960836 1891 80.91.229.2 (30 May 2006 03:47:16 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 30 May 2006 03:47:16 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 30 05:47:14 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 1FkvCL-0001lv-Cb for ged-emacs-devel@m.gmane.org; Tue, 30 May 2006 05:47:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FkvCK-0001BH-SO for ged-emacs-devel@m.gmane.org; Mon, 29 May 2006 23:47:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FkvC9-0001Af-F7 for emacs-devel@gnu.org; Mon, 29 May 2006 23:47:01 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FkvC8-0001AS-7P for emacs-devel@gnu.org; Mon, 29 May 2006 23:47:00 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FkvC8-0001AP-4N for emacs-devel@gnu.org; Mon, 29 May 2006 23:47:00 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FkvHq-00086C-1n for emacs-devel@gnu.org; Mon, 29 May 2006 23:52:54 -0400 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.34) id 1FkvC7-0007HQ-Ar; Mon, 29 May 2006 23:46:59 -0400 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:55463 Archived-At: Here's a definition I came across that combines absolute and relative comparisons in a way that is better than what I proposed. (I added the defaults for the fuzz factors.) (defun approx-equal (x y &optional rfuzz afuzz) "Return non-nil if numbers X and Y are approximately equal. RFUZZ is a relative fuzz factor. AFUZZ is an absolute fuzz factor. RFUZZ defaults to 1.0e-8. AFUZZ defaults to (/ RFUZZ 10). The algorithm is: (< (abs (- X Y)) (+ AFUZZ (* RFUZZ (+ (abs X) (abs Y)))))." (setq rfuzz (or rfuzz 1.0e-8) afuzz (or afuzz (/ rfuzz 10))) (< (abs (- x y)) (+ afuzz (* rfuzz (+ (abs x) (abs y)))))) Since this is simple and clean, let's use it as the example. Or else, let's simplify the example so it returns nil directly when it sees 0 as an argument.