[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Elisp manual, node "Comparison of Numbers"

From: Richard Stallman
Subject: Re: Elisp manual, node "Comparison of Numbers"
Date: Mon, 29 May 2006 23:46:59 -0400

    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 via email to

[Prev in Thread] Current Thread [Next in Thread]