From 29abf3a73b16034dcc4341c6dcb2b30aea05f4fe Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Fri, 30 Nov 2018 00:53:05 +0000 Subject: [PATCH] Add some more sqrt edge cases. --- tests/runtime/test-arith.scm | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/runtime/test-arith.scm b/tests/runtime/test-arith.scm index de18b6854..0903e396e 100644 --- a/tests/runtime/test-arith.scm +++ b/tests/runtime/test-arith.scm @@ -647,13 +647,38 @@ USA. (lambda (z t) (assert-<= (relerr t (angle z)) 1e-15))) -(define-enumerated-test 'sqrt +(define-enumerated-test 'sqrt-exact `((0 0) (0. 0.) (1 1) (1. 1.) + ;; Square root of perfect square should be exact. (4 2) (4. 2.) + ;; Square root of perfect square x times 2i should be exactly x+xi. + (+2i 1+1i ,expect-failure) + (+8i 2+2i ,expect-failure) + (+18i 3+3i ,expect-failure) + (+32i 4+4i ,expect-failure) + (+2.i 1.+1.i ,expect-failure) + (+8.i 2.+2.i ,expect-failure) + (+18.i 3.+3.i ,expect-failure) + (+32.i 4.+4.i ,expect-failure) + ;; Likewise, sqrt of perfect square x times -2i should be x-xi. + (-2i 1-1i ,expect-failure) + (-8i 2-2i ,expect-failure) + (-18i 3-3i ,expect-failure) + (-32i 4-4i ,expect-failure) + (-2.i 1.-1.i ,expect-failure) + (-8.i 2.-2.i ,expect-failure) + (-18.i 3.-3.i ,expect-failure) + (-32.i 4.-4.i ,expect-failure) + ;; Handle signed zero carefully. + (+0.i 0.+0.i) + (-0.i 0.-0.i ,expect-failure) + (-0.+0.i +0.+0.i) + (-0.-0.i +0.-0.i ,expect-failure) + ;; Treat infinities carefully around branch cuts. (-inf.0 +inf.0i) (+inf.0 +inf.0) (-inf.0+1.i +inf.0i ,expect-failure) @@ -666,6 +691,7 @@ USA. (1.+inf.0i +inf.0+inf.0i) (-1.-inf.0i -inf.0+inf.0i ,expect-failure) (-1.+inf.0i +inf.0+inf.0i) + ;; NaN should be preserved. (,(flo:qnan 1234) ,(flo:qnan 1234))) (lambda (z r #!optional xfail) (with-expected-failure xfail -- 2.25.1