~ chicken-core (chicken-5) d46f0aeb2c8ece5670de9d4d6a6af19a0f471125


commit d46f0aeb2c8ece5670de9d4d6a6af19a0f471125
Author:     Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Wed May 29 19:05:32 2013 +0200
Commit:     Jim Ursetto <zbigniewsz@gmail.com>
CommitDate: Thu May 30 09:08:34 2013 -0500

    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.

diff --git a/tests/library-tests.scm b/tests/library-tests.scm
index 12d96b51..7cfca2cd 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))
 
Trap