From 0674c0d2e1147089e504db204b5c7a0d568bbe6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= <daniel@turtleware.eu> Date: Thu, 22 Dec 2016 21:02:00 +0100 Subject: [PATCH] numbers: atan.ieee.1: we test signed 0 later So we may simplify these tests and check for the exact sign of the result. --- numbers/atan.lsp | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/numbers/atan.lsp b/numbers/atan.lsp index 4e084d4e..07375410 100644 --- a/numbers/atan.lsp +++ b/numbers/atan.lsp @@ -128,31 +128,23 @@ ;;; ieee-fp tests (deftest atan.ieee.1 :description "Verify if atan handles 0.0 correctly" - (flet ((pip (a b) - ;; we are not testing accuracy, so this simplified - ;; predicate would be sufficient for our needs. We are also - ;; not interested in sign of the result, because we don't - ;; know whenever zero is signed or not. - (<= (abs (- (abs a) (abs b))) 0.01))) + (flet ((+pi-p (elt) (< (abs (- pi elt)) 0.01)) + (+pi/2-p (elt) (< (abs (+ (/ pi 2) elt)) 0.01)) + (-pi/2-p (elt) (< (abs (- (/ pi 2) elt)) 0.01))) + ;; (atan +-0 +(anything-but-nan)) -> +-0 + ;; (atan +-0 -(anything-but-nan)) -> +-pi + ;; (atan +-(anything-but-0/nan) 0) -> +-pi/2 (every #'identity - (append - ;; (atan +-0 +(anything-but-nan)) -> +-0 - ;; (atan +-0 -(anything-but-nan)) -> +-pi - (map 'list (lambda (n) - ;; notice, that we don't test a case, where - ;; both arguments are 0.0, because if - ;; implementation doesn't support signed 0 - ;; result is undefined. - (and (zerop (atan -0.0 n)) - (zerop (atan +0.0 n)) - (pip pi (atan +0.0 (- n))) - (pip pi (atan -0.0 (- n))))) - (remove-if-not #'plusp *floats*)) - ;; (atan +-(anything-but-0/nan) 0) -> +-pi/2 - (map 'list (lambda (n) - (and (pip (* +1/2 pi) (atan n +0.0)) - (pip (* -1/2 pi) (atan n -0.0)))) - (remove-if #'zerop *floats*))))) + (map 'list (lambda (n) + ;; notice, that we don't test a case, where + ;; both arguments are 0.0, because if + ;; implementation doesn't support signed 0 + ;; result is undefined. + (and (zerop (atan 0.0 n)) + (+pi-p (atan 0.0 (- n))) + (+pi/2-p (atan n 0.0)) + (-pi/2-p (atan (- n) 0.0)))) + (remove-if-not #'plusp *floats*)))) T) (deftest atan.ieee.2 :description "Verify ATAN handling signed zero" -- GitLab