>From d4f4ed53a292de6b25b64e7e1e2251bed06f92ff Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Wed, 29 May 2013 19:05:32 +0200 Subject: [PATCH] Use inexact comparison for flonum tests. GCC optimizes trig functions (by inlining? pre-calculating?), which causes answers to be slightly different from the libc implementation. Thanks to John Long for reporting and Sven Hartrumpf for initial patch. --- tests/library-tests.scm | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/tests/library-tests.scm b/tests/library-tests.scm index 12d96b5..7cfca2c 100644 --- a/tests/library-tests.scm +++ b/tests/library-tests.scm @@ -207,28 +207,31 @@ ;; fp-math -(assert (= (sin 42.0) (fpsin 42.0))) -(assert (= (cos 42.0) (fpcos 42.0))) -(assert (= (tan 42.0) (fptan 42.0))) -(assert (= (asin 0.5) (fpasin 0.5))) -(assert (= (acos 0.5) (fpacos 0.5))) -(assert (= (atan 0.5) (fpatan 0.5))) -(assert (= (atan 42.0 1.2) (fpatan2 42.0 1.2))) -(assert (= (atan 42.0 1) (fpatan2 42.0 1.0))) -(assert (= (atan 42 1.0) (fpatan2 42.0 1.0))) -(assert (= (exp 42.0) (fpexp 42.0))) -(assert (= (log 42.0) (fplog 42.0))) -(assert (= (expt 42.0 3.5) (fpexpt 42.0 3.5))) -(assert (= (sqrt 42.0) (fpsqrt 42.0))) -(assert (= 43.0 (fpround 42.5))) -(assert (= -43.0 (fpround -42.5))) -(assert (= 42.0 (fpround 42.2))) -(assert (= 42.0 (fptruncate 42.5))) -(assert (= -42.0 (fptruncate -42.5))) -(assert (= 42.0 (fpfloor 42.2))) -(assert (= -43.0 (fpfloor -42.5))) -(assert (= 43.0 (fpceiling 42.5))) -(assert (= -42.0 (fpceiling -42.2))) +(define (inexact= a b) + (< (abs (- 1 (abs (/ a b)))) 1e-10)) + +(assert (inexact= (sin 42.0) (fpsin 42.0))) +(assert (inexact= (cos 42.0) (fpcos 42.0))) +(assert (inexact= (tan 42.0) (fptan 42.0))) +(assert (inexact= (asin 0.5) (fpasin 0.5))) +(assert (inexact= (acos 0.5) (fpacos 0.5))) +(assert (inexact= (atan 0.5) (fpatan 0.5))) +(assert (inexact= (atan 42.0 1.2) (fpatan2 42.0 1.2))) +(assert (inexact= (atan 42.0 1) (fpatan2 42.0 1.0))) +(assert (inexact= (atan 42 1.0) (fpatan2 42.0 1.0))) +(assert (inexact= (exp 42.0) (fpexp 42.0))) +(assert (inexact= (log 42.0) (fplog 42.0))) +(assert (inexact= (expt 42.0 3.5) (fpexpt 42.0 3.5))) +(assert (inexact= (sqrt 42.0) (fpsqrt 42.0))) +(assert (inexact= 43.0 (fpround 42.5))) +(assert (inexact= -43.0 (fpround -42.5))) +(assert (inexact= 42.0 (fpround 42.2))) +(assert (inexact= 42.0 (fptruncate 42.5))) +(assert (inexact= -42.0 (fptruncate -42.5))) +(assert (inexact= 42.0 (fpfloor 42.2))) +(assert (inexact= -43.0 (fpfloor -42.5))) +(assert (inexact= 43.0 (fpceiling 42.5))) +(assert (inexact= -42.0 (fpceiling -42.2))) (assert (not (fpinteger? 2.3))) (assert (fpinteger? 1.0)) -- 1.8.2.3