mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-23 04:52:42 -08:00
tests: add approx= function
This commit is contained in:
parent
904333a5a3
commit
6d627a3fd9
1 changed files with 14 additions and 0 deletions
|
|
@ -128,3 +128,17 @@ as a second value."
|
|||
(format ,stream ,string ,@args))
|
||||
(multiple-value-prog1 (progn ,@body)
|
||||
(delete-file ,var)))))
|
||||
|
||||
|
||||
;;; Approximate equality function
|
||||
(defun approx= (x y &optional (eps (epsilon x)))
|
||||
(<= (abs (/ (- x y) (max (abs x) 1))) eps))
|
||||
|
||||
(defun epsilon (number)
|
||||
(etypecase number
|
||||
(complex (* 2 (epsilon (realpart number)))) ;; crude
|
||||
(short-float short-float-epsilon)
|
||||
(single-float single-float-epsilon)
|
||||
(double-float double-float-epsilon)
|
||||
(long-float long-float-epsilon)
|
||||
(rational 0)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue