From 64d38800fe38fd44969db4a666a11794d496febf Mon Sep 17 00:00:00 2001 From: "Thomas M. Hermann" Date: Thu, 22 May 2008 11:47:09 +0000 Subject: [PATCH] [project @ COMPLEX-EQUAL predicate defined.] --- lisp-unit.lisp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lisp-unit.lisp b/lisp-unit.lisp index d4f58c3..14c3fe3 100644 --- a/lisp-unit.lisp +++ b/lisp-unit.lisp @@ -106,7 +106,8 @@ For more information, see lisp-unit.html. #:assert-equality #:assert-prints #:assert-true #:get-test-code #:get-tests #:remove-all-tests #:remove-tests - #:logically-equal #:set-equal #:float-equal + #:logically-equal #:set-equal + #:float-equal #:complex-equal #:use-debugger #:with-test-listener) ) @@ -445,4 +446,29 @@ than some epsilon." (> single-float-epsilon (abs (- x y)))) (t nil)))) +;;; (COMPLEX-EQUAL x y :epsilon) => true or false Return true if the +;;; absolute difference of the real components and the absolute +;;; difference of the imaginary components is less then epsilon. If an +;;; epsilon is not specified and either x or y is (complex +;;; single-float), the single-float-epsilon is used. +(defun complex-equal (x y &key (epsilon nil epsilon-p)) + "Return true if the absolute difference between Re(x),Re(y) and the +absolute difference between Im(x),Im(y) is less than epsilon." + (and + (complexp x) + (complexp y) + (cond + (epsilon-p + (> epsilon (max (abs (realpart (- x y))) + (abs (imagpart (- x y)))))) + ((and (typep x '(complex double-float)) + (typep y '(complex double-float))) + (> double-float-epsilon (max (abs (realpart (- x y))) + (abs (imagpart (- x y)))))) + ((or (typep x '(complex single-float)) + (typep y '(complex single-float))) + (> single-float-epsilon (max (abs (realpart (- x y))) + (abs (imagpart (- x y)))))) + (t nil)))) + (provide "lisp-unit") -- 2.11.4.GIT