Rudolf Adamkovič Personal site


Practice implementation

(defun my-within-order-of-magnitude-p (x y &optional n b)
  "Return t if X is within N orders of base-B magnitudes of Y.

By default, check for 1 order of base-10 magnitude."
  (let ((n (or n 1))
        (b (or b 10)))
    (and (> (/ (float x) y) (expt b (- 0 n)))
         (< (/ (float x) y) (expt b (+ 0 n))))))
(and (my-within-order-of-magnitude-p 1.00 1.01)
     (my-within-order-of-magnitude-p 1000 1010))
t
(seq-map (lambda (number)
           (list number
                 (my-within-order-of-magnitude-p 1 number)))
         (number-sequence 1 15))
1t
2t
3t
4t
5t
6t
7t
8t
9t
10nil
11nil
12nil
13nil
14nil
15nil

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.