From 365ccacef1a18307cfcdfe2f1963e56d4b5dc3fe Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 19 Nov 2018 01:07:29 +0000 Subject: [PATCH] Tweak acos tests to clarify and reduce rounding errors. --- tests/runtime/test-arith.scm | 70 +++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/tests/runtime/test-arith.scm b/tests/runtime/test-arith.scm index de6b51446..966d67236 100644 --- a/tests/runtime/test-arith.scm +++ b/tests/runtime/test-arith.scm @@ -477,6 +477,9 @@ USA. (flo:-inf.0)) assert-not-integer) +(define pi 3.1415926535897932) +(define pi/2 (/ pi 2)) + (define-test 'asin-0 (lambda () (assert-eqv (asin 0) 0) @@ -488,14 +491,14 @@ USA. (define-enumerated-test 'asin (vector - (vector (/ (- (sqrt 6) (sqrt 2)) 4) (/ 3.1415926535897932 12)) - (vector (/ (sqrt (- 2 (sqrt 2))) 2) (/ 3.1415926535897932 8)) - (vector 1/2 (/ 3.1415926535897932 6)) - (vector (rsqrt 2) (/ 3.1415926535897932 4)) - (vector (/ (sqrt 3) 2) (/ 3.1415926535897932 3)) - (vector (/ (sqrt (+ 2 (sqrt 2))) 2) (* 3.1415926535897932 3/8)) - (vector (/ (+ (sqrt 6) (sqrt 2)) 4) (* 3.1415926535897932 5/12)) - (vector 1 (/ 3.1415926535897932 2)) + (vector (/ (- (sqrt 6) (sqrt 2)) 4) (/ pi 12)) + (vector (/ (sqrt (- 2 (sqrt 2))) 2) (/ pi 8)) + (vector 1/2 (/ pi 6)) + (vector (rsqrt 2) (/ pi 4)) + (vector (/ (sqrt 3) 2) (/ pi 3)) + (vector (/ (sqrt (+ 2 (sqrt 2))) 2) (* pi 3/8)) + (vector (/ (+ (sqrt 6) (sqrt 2)) 4) (* pi 5/12)) + (vector 1 (/ pi 2)) (vector 2 1.5707963267948966+1.3169578969248166i 'xfail) (vector 2.+0.i 1.5707963267948966+1.3169578969248166i) (vector 2.-0.i 1.5707963267948966-1.3169578969248166i) @@ -529,37 +532,38 @@ USA. (assert-eqv (acos 1.) 0.) (assert-eqv (acos (identity-procedure 1.)) 0.))) -(define pi/2 (/ 3.1415926535897932 2)) - (define-enumerated-test 'acos (vector - (vector (/ (+ (sqrt 6) (sqrt 2)) 4) (/ 3.1415926535897932 12)) - (vector (/ (sqrt (+ 2 (sqrt 2))) 2) (/ 3.1415926535897932 8)) - (vector (/ (sqrt 3) 2) (/ 3.1415926535897932 6)) - (vector (rsqrt 2) (/ 3.1415926535897932 4)) - (vector 1/2 (/ 3.1415926535897932 3)) - (vector (/ (sqrt (- 2 (sqrt 2))) 2) (* 3.1415926535897932 3/8)) - (vector (/ (- (sqrt 6) (sqrt 2)) 4) (* 3.1415926535897932 5/12)) - (vector 0 (/ 3.1415926535897932 2)) + (vector (/ (+ (sqrt 6) (sqrt 2)) 4) (/ pi 12)) + (vector (/ (sqrt (+ 2 (sqrt 2))) 2) (/ pi 8)) + (vector (/ (sqrt 3) 2) (/ pi 6)) + (vector (rsqrt 2) (/ pi 4)) + (vector 1/2 (/ pi 3)) + (vector (/ (sqrt (- 2 (sqrt 2))) 2) (* pi 3/8)) + (vector (/ (- (sqrt 6) (sqrt 2)) 4) (* pi 5/12)) + (vector 0 (/ pi 2)) (vector 2 (* +i (log (- 2 (sqrt 3)))) 'xfail) (vector 2.+0.i (* +i (log (- 2 (sqrt 3))))) (vector 2.-0.i (* -i (log (- 2 (sqrt 3))))) + (vector -2 (+ pi (* +i (log (- 2 (sqrt 3)))))) + (vector -2.+0.i (+ pi (* +i (log (- 2 (sqrt 3)))))) + (vector -2.-0.i (+ pi (* -i (log (- 2 (sqrt 3)))))) ;; -i log(z + sqrt(z^2 - 1)) - ;; = -i log(z + sqrt(z - 1) sqrt(z + 1)) - ;; = -i log(z (1 + sqrt(z - 1) sqrt(z + 1)/z)) - ;; = -i log(z) - i log1p(sqrt(z - 1) sqrt(z + 1)/z) - (vector 1e150 (* +i (+ (log 1e150) (log 2))) 'xfail) - (vector 1e150+0.i (* +i (+ (log 1e150) (log 2))) 'xfail) - (vector 1e150-0.i (* -i (+ (log 1e150) (log 2))) 'xfail) - (vector -1e150 (+ pi/2 (* +i (+ (log 1e150) (log 2)))) 'xfail) - (vector -1e150+0.i (+ pi/2 (* +i (+ (log 1e150) (log 2)))) 'xfail) - (vector -1e150-0.i (+ pi/2 (* -i (+ (log 1e150) (log 2)))) 'xfail) - (vector 1e300 (* +i (+ (log 1e300) (log 2))) 'xfail) - (vector 1e300+0.i (* +i (+ (log 1e300) (log 2))) 'xfail) - (vector 1e300-0.i (* -i (+ (log 1e300) (log 2))) 'xfail) - (vector -1e300 (+ pi/2 (* +i (+ (log 1e300) (log 2)))) 'xfail) - (vector -1e300+0.i (+ pi/2 (* +i (+ (log 1e300) (log 2)))) 'xfail) - (vector -1e300-0.i (+ pi/2 (* -i (+ (log 1e300) (log 2)))) 'xfail)) + ;; \approx -i log(z + sqrt(z^2)) + ;; = -i log(z + z) + ;; = -i log(2 z) + (vector 1e150 (* +i (log (* 2 1e150))) 'xfail) + (vector 1e150+0.i (* +i (log (* 2 1e150))) 'xfail) + (vector 1e150-0.i (* -i (log (* 2 1e150))) 'xfail) + (vector -1e150 (+ pi (* +i (log (* 2 1e150)))) 'xfail) + (vector -1e150+0.i (+ pi (* +i (log (* 2 1e150)))) 'xfail) + (vector -1e150-0.i (+ pi (* -i (log (* 2 1e150)))) 'xfail) + (vector 1e300 (* +i (log (* 2 1e300))) 'xfail) + (vector 1e300+0.i (* +i (log (* 2 1e300))) 'xfail) + (vector 1e300-0.i (* -i (log (* 2 1e300))) 'xfail) + (vector -1e300 (+ pi (* +i (log (* 2 1e300)))) 'xfail) + (vector -1e300+0.i (+ pi (* +i (log (* 2 1e300)))) 'xfail) + (vector -1e300-0.i (+ pi (* -i (log (* 2 1e300)))) 'xfail)) (lambda (v) (let ((x (vector-ref v 0)) (t (vector-ref v 1)) -- 2.25.1