unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Richard Stallman <rms@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Elisp manual, node "Comparison of Numbers"
Date: Mon, 29 May 2006 23:46:59 -0400	[thread overview]
Message-ID: <E1FkvC7-0007HQ-Ar@fencepost.gnu.org> (raw)
In-Reply-To: <MEEKKIABFKKDFJMPIOEBIENEDBAA.drew.adams@oracle.com>

    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.

  reply	other threads:[~2006-05-30  3:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-29 13:20 Elisp manual, node "Comparison of Numbers" Drew Adams
2006-05-29 13:33 ` David Kastrup
2006-05-29 13:42   ` Kim F. Storm
2006-05-29 13:54     ` Lennart Borgman
2006-05-29 14:08       ` David Kastrup
2006-05-29 14:18         ` Lennart Borgman
2006-05-29 14:23           ` David Kastrup
2006-05-29 14:40             ` Lennart Borgman
2006-05-29 21:28   ` Richard Stallman
2006-05-29 13:40 ` Lennart Borgman
2006-05-29 18:14   ` Drew Adams
2006-05-30  3:46     ` Richard Stallman [this message]
2006-05-29 19:23 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1FkvC7-0007HQ-Ar@fencepost.gnu.org \
    --to=rms@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).