~ chicken-core (chicken-5) /tests/numbers-test.scm
Trap1;;;; numbers-test.scm23(include "test.scm")45(import (chicken bitwise)6 (chicken fixnum)7 (chicken flonum)8 (chicken format)9 (chicken platform)10 (chicken time))1112;; The default "comparator" doesn't know how to deal with extended number types13(current-test-comparator14 (lambda (exp act)15 (or (equal? exp act)16 (if (or (and (cplxnum? exp) (number? act))17 (and (cplxnum? act) (number? exp)))18 (and (< (abs (real-part (- exp act)))19 (current-test-epsilon))20 (< (abs (imag-part (- exp act)))21 (current-test-epsilon)))22 (and (number? exp)23 (inexact? exp)24 (< (abs (- 1 (abs (if (zero? act) (+ 1 exp) (/ exp act)))))25 (current-test-epsilon)))))))2627(test-begin "numbers")2829(current-test-epsilon 0) ;; We want exact comparisons3031(define max-fix most-positive-fixnum)32(define min-fix most-negative-fixnum)33;; The minimal bignum in the sense that any smaller makes it a fixnum34(define min-big (+ most-positive-fixnum 1))3536(define 64-bits? (feature? #:64bit))3738(define (show x)39 (print (and x (number->string x)))40 x)4142;(set-gc-report! #t)4344(define max2 (+ max-fix max-fix))4546(define b1 (+ 22 max2)) ; 2147483668 or 46116860184273879284748(define c1 (make-rectangular 33 44))49(define c2 (make-rectangular -1.2 44))5051(define b2 (- min-fix 22))52(define r1 (/ 33 44))53(define r2 (/ 1000 44))5455;; Found with the pi-ratios benchmark (find-pi 10 20 50)56(define pi 3.14159265358979323881089001960817518141234854964894)57(define ratpi 314159265358979323881089001960817518141234854964894/100000000000000000000000000000000000000000000000000)5859(test-group "basic constructors"60 (test-assert "some bignum (twice maxint)" (show max2))61 (test-assert "some other bignum (2147483668 or 9223372036854775828)" (show b1))62 (test-assert "negative bignum" (show b2))63 (test-assert "exact complex" (show c1))64 (test-assert "inexact complex" (show c2))65 (test-assert "rational" (show r1))66)6768(test-group "addition"69 (test-equal "+: no arguments" (+) 0)70 (test-equal "+: single argument" (+ 33) 33)71 (test-equal "+: adding fixnums" (+ 33 44) 77)72 (test-equal "+: adding fixnums (2nd negative)" (+ 33 -44) -11)73 (test-equal "+: adding fix/flo" (+ 33 44.5) 77.5)74 (test-assert "+: adding fix/big" (show (+ 22 max2)))75 (test-assert "+: adding fix/rat" (show (+ 22 r1)))76 (test-equal "+: adding fix/complex" (+ 99 c1) (make-rectangular 132 44))77 (test-equal "+: adding complex/fix (inexact)" (+ c2 99) (make-rectangular 97.8 44))78 (test-equal "+: flo/flo" (+ 3.4 5.6) 9.0)79 (test-equal "+: flo/big"80 (+ 3.4 b1)81 (if 64-bits? 9223372036854775809.4 2147483671.4))82 (test-assert "+: flo/rat" (show (+ 33.4 r1)))83 (test-equal "+: flo/comp" (+ 3.4 c1) (make-rectangular 36.4 44))84 (test-assert "+: big/rat" (show (+ b1 r1)))85 (test-equal "+: comp+comp" (+ c1 c1) (make-rectangular 66 88))86 (test-equal "+: comp+comp (inexact)" (+ c1 c2) (make-rectangular 31.8 88))87 (test-equal "+: multiarg" (+ 33 44 55) 132)88)8990(test-group "subtraction"9192 (test-equal "-: negate fix" (- 33) -33)93 (test-equal "-: negate most negative fix" (- min-fix) min-big)94 (test-equal "abs: most negative fix" (abs most-negative-fixnum) min-big)95 (test-equal "-: negate flo" (- 33.2) -33.2)96 (test-assert "-: negate rat" (show (- r1)))97 (test-equal "-: double-negate big" (- (- b1)) b1)98 (test-equal "-: negate comp" (- c1) (make-rectangular -33 -44))99 (test-equal "-: fixnums" (- 33 44) -11)100 (test-equal "-: fixnums (2nd negative)" (- 33 -44) 77)101 (test-assert "-: fixnums (overflow)" (show (- min-fix min-fix)))102 (test-equal "-: fix/flo" (- 33 44.5) -11.5)103 (test-equal "-: flo/fix" (- 44.5 33) 11.5)104 (test-assert "-: fix/big" (show (- 22 b2)))105 (test-assert "-: big/fix" (show (- b2 22)))106 (test-equal "-: big/fix (normalizing to fix)" (- min-big 1) max-fix)107 (test-assert "-: fix/rat" (show (- 22 r1)))108 (test-assert "-: rat/fix" (show (- r1 22)))109 (test-equal "-: fix/complex" (- 99 c1) (make-rectangular 66 -44))110 (test-equal "-: complex/fix" (- c1 99) (make-rectangular -66 44))111 (test-equal "-: complex/fix (inexact)" (- c2 99) (make-rectangular -100.2 44))112 (test-equal "-: fix/complex (inexact)" (- 99 c2) (make-rectangular 100.2 -44))113 (test-equal "-: fix/complex (negative im)" (- 99 1+2i) 98-2i)114 (test-equal "-: fix/complex (negative im, inexact)" (- 99 1.0+2.0i) 98.0-2.0i)115 (test-equal "-: fix/complex (negative real, inexact)" (- 99 -1.0+2.0i) 100.0-2.0i)116 (test-equal "-: rat/complex (negative real)" (- 3/2 -1+2i) 5/2-2i)117118 (parameterize ((current-test-epsilon 1e-10))119 (test-equal "-: flo/flo" (- 5.6 3.4) 2.2))120121 (test-assert "-: flo/big" (show (- 3.4 b1)))122 (test-assert "-: big/flo" (show (- b1 3.4)))123 (test-assert "-: flo/rat" (show (- 3.4 r1)))124 (test-assert "-: rat/flo" (show (- r1 3.4)))125 (test-assert "-: big/rat" (show (- b1 r1)))126 (test-assert "-: rat/big" (show (- r1 b1)))127 (test-equal "-: flo/comp" (- 3.4 c1) (make-rectangular -29.6 -44))128 (test-equal "-: comp/flo" (- c1 3.4) (make-rectangular 29.6 44))129 (test-equal "-: comp-comp" (- c1 c1) 0)130 (test-equal "-: comp-comp (inexact)" (- c1 c2) 34.2)131 (test-equal "-: multiarg" (- 33 44 55) -66)132)133134135(test-group "multiplication"136137 (test-equal "*: no arguments" (*) 1)138 (test-equal "*: single argument" (* 33) 33)139 (test-equal "*: multiplying fixnums" (* 33 44) 1452)140 (test-equal "*: multiplying fixnums (2nd negative)" (* 33 -44) -1452)141 (test-equal "*: multiplying fix/flo" (* 33 44.5) 1468.5)142 (test-assert "*: multiplying fix/big (-> 47244640212)" (show (* 22 max2)))143 (test-assert "*: multiplying fix/rat" (show (* 33 r1)))144 (test-equal "*: multiplying fix/complex" (* 99 c1) (make-rectangular 3267 4356))145 (test-equal "*: multiplying complex/fix (inexact)" (* c2 99) (make-rectangular -118.8 4356.0))146 (test-equal "*: multiplying most negative fixnum by one (edge case)"147 (list (* most-negative-fixnum 1) (fixnum? (* most-negative-fixnum 1)))148 (list most-negative-fixnum #t))149 (test-equal "*: flo/flo" (* 3.4 5.6) 19.04)150 (test-equal "*: flo/big"151 (* 0.001 b1)152 (if 64-bits? 9223372036854775.806 2147483.668))153 (test-assert "*: flo/rat" (show (* 3.4 r1)))154 (test-assert "*: big/rat" (show (* b1 r1)))155 (test-equal "*: flo/comp" (* 3.4 c1) (make-rectangular 112.2 149.6))156 (test-equal "*: comp*comp" (* c1 c1) (make-rectangular -847 2904))157 (test-equal "*: comp*comp (inexact)" (* c1 c2) (make-rectangular -1975.6 1399.2))158 (test-equal "*: multiarg" (* 33 44 55) 79860)159)160161(test-group "division"162163 (test-assert "/: rec. fix" (show (/ 33)))164 (test-assert "/: rec. flo" (show (/ 33.2)))165 (test-assert "/: rec. rat" (show (/ r1)))166 (test-assert "/: rec. big" (show (/ b1)))167 (test-assert "/: rec. comp" (/ c1))168 (test-assert "/: fixnums" (show (/ 33 44)))169 (test-equal "/: fixnums (both negative, fixnum result)" (show (/ -2 -2)) 1)170 (test-assert "/: fixnums (2nd negative)" (show (/ 33 -44)))171 (test-assert "/: fixnums" (show (/ min-fix min-fix)))172 (test-equal "/: fix/flo" (/ 33 44.5) (fp/ 33.0 44.5))173 (test-equal "/: flo/fix" (/ 44.5 33) (fp/ 44.5 33.0))174 (test-assert "/: fix/big" (show (/ 22 b2)))175 (test-assert "/: big/fix" (show (/ b2 22)))176 (test-assert "/: fix/rat" (show (/ 22 r1)))177 (test-assert "/: rat/fix" (show (/ r1 22)))178 (test-assert "/: fix/complex" (show (/ 99 c1)))179 (test-assert "/: complex/fix" (show (/ c1 99)))180 (test-assert "/: complex/fix (inexact)" (show (- c2 99)))181 (test-assert "/: fix/complex (inexact)" (show (- 99 c2)))182 (test-equal "/: flo/flo" (/ 5.6 3.4) (fp/ 5.6 3.4))183 (test-assert "/: flo/big" (show (/ 3.4 b1)))184 (test-assert "/: big/flo" (show (/ b1 3.4)))185 (test-assert "/: flo/rat" (show (/ 3.4 r1)))186 (test-assert "/: rat/flo" (show (/ r1 3.4)))187 (test-assert "/: big/rat" (show (/ b1 r1)))188 (test-assert "/: rat/big" (show (/ r1 b1)))189 (test-assert "/: rat/rat" (show (/ r1 r1)))190 (test-assert "/: flo/comp" (show (/ 3.4 c1)))191 (test-assert "/: comp/flo" (show (/ c1 3.4)))192 (test-assert "/: comp/comp" (show (/ c1 c1)))193 (test-assert "/: comp/comp (inexact)" (show (/ c1 c2)))194 (test-equal "/: rat/complex" (/ 1/2 1+2i) 1/10-1/5i)195 (test-equal "/: rat/complex (negative im)" (/ 1/2 1-2i) 1/10+1/5i)196 (test-equal "/: rat/complex (negative real)" (/ 1/2 -1+2i) -1/10-1/5i)197 (test-equal "/: rat/complex (negative real&im)" (/ 1/2 -1-2i) -1/10+1/5i)198199 (test-assert "/: multiarg" (show (/ 66 2 44)))200 (test-error "/: div fixnum by 0" (/ 33 0))201 ;; R7RS says it is an error if any but the first argument is an exact202 ;; zero. R5RS doesn't say anything at all (??).203 (test-error "/: div flonum by 0" (/ 33.0 0))204 (test-equal "/: div fixnum by 0.0" (/ 33 0.0) +inf.0)205 (test-equal "/: div flonum by 0.0" (/ 33.0 0.0) +inf.0)206 (test-equal "/: div by 0 (inexact)" (/ 33 0.0) +inf.0)207 (test-assert "/: big result" (show (/ b1 2)))208)209210(test-group "quotient"211 (test-equal "quotient: fix/fix" (quotient 22 11) 2)212 (test-equal "quotient: fix/big" (quotient 22 b1) 0)213 (test-equal "quotient: fix/big (most negative)" (quotient min-fix (- min-fix)) -1)214 (test-equal "quotient: big/fix (most negative)" (quotient (- min-fix) min-fix) -1)215 (test-equal "quotient: fix/fix (most negative)" (quotient min-fix -1) (* min-fix -1))216 (test-equal "quotient: flo/flo" (quotient 22.0 11.0) 2.0)217 (test-equal "quotient: fix/flo" (quotient 22 11.0) 2.0)218 (test-equal "quotient: flo/fix" (quotient 22.0 11) 2.0)219 (test-equal "quotient: flo/big" (quotient 22.0 b1) 0.0)220 (test-equal "quotient: big/flo" (quotient b1 (/ b1 2.0)) 2.0)221 (test-equal "quotient: big/big" (quotient (- min-fix) (- min-fix)) 1)222 (test-equal "quotient: big/big" (quotient (+ (- min-fix) 5) (- min-fix)) 1)223224 (test-error "quotient: flo/flo (fractional)" (quotient 23.0 11.5))225 (test-error "quotient: fix/flo (fractional)" (quotient 23 11.5))226 (test-error "quotient: flo/fix (fractional)" (quotient 13.5 6))227)228229(test-group "remainder"230 (test-equal "remainder: fix/fix" (remainder 22 11) 0)231 (test-equal "remainder: fix/big" (remainder 22 b1) 22)232 (test-equal "remainder: fix/big (most negative)" (remainder min-fix (- min-fix)) 0)233 (test-equal "remainder: big/fix (most negative)" (remainder (- min-fix) min-fix) 0)234 (test-equal "remainder: big/big" (remainder (- min-fix) (- min-fix)) 0)235 (test-equal "remainder: big/big" (remainder (+ (- min-fix) 5) (- min-fix)) 5)236237 (test-equal "remainder: flo/flo" (remainder 22.0 11.0) 0.0)238 (test-equal "remainder: fix/flo" (remainder 22 11.0) 0.0)239 (test-equal "remainder: flo/fix" (remainder 22.0 11) 0.0)240 (unless 64-bits? ;; We lose so much precision when converting to double this makes no sense241 (test-equal "remainder: flo/big" (remainder 22.0 b1) 22.0))242243 (test-error "remainder: flo/flo (fractional)" (remainder 22.5 2.25))244 (test-error "remainder: fix/flo (fractional)" (remainder 6 12.5))245 (test-error "remainder: flo/fix (fractional)" (remainder 13.5 6))246 (unless 64-bits?247 (test-error "remainder: flo/big (fractional)" (remainder (+ b1 0.5) b1)))248)249250(test-group "quotient&remainder"251 (test-equal "quotient&remainder: fix/fix"252 (receive (quotient&remainder 22 11)) '(2 0))253 (test-equal "quotient&remainder: fix/big"254 (receive (quotient&remainder 22 b1)) '(0 22))255 (test-equal "quotient&remainder: fix/big (most negative)"256 (receive (quotient&remainder min-fix (- min-fix))) '(-1 0))257 (test-equal "quotient&remainder: big/fix (most negative)"258 (receive (quotient&remainder (- min-fix) min-fix)) '(-1 0))259 (test-equal "quotient&remainder: fix/fix (most negative)"260 (receive (quotient&remainder min-fix -1)) `(,(* min-fix -1) 0))261 (test-equal "quotient&remainder: big/big" (receive (quotient&remainder (- min-fix) (- min-fix)))262 '(1 0))263 (test-equal "quotient&remainder: big/big" (receive (quotient&remainder (+ (- min-fix) 5) (- min-fix)))264 '(1 5))265266 (test-equal "quotient&remainder: flo/flo"267 (receive (quotient&remainder 22.0 4.0)) '(5.0 2.0))268 (test-equal "quotient&remainder: flo/fix"269 (receive (quotient&remainder 22.0 4)) '(5.0 2.0))270 (test-equal "quotient&remainder: fix/flo"271 (receive (quotient&remainder 22 4.0)) '(5.0 2.0))272 (test-error "quotient&remainder: flo/fix (fractional)"273 (receive (quotient&remainder 0.1 2)))274 (test-error "quotient&remainder: flo/big (fractional)"275 (receive (quotient&remainder 0.5 b1)))276 (test-error "quotient&remainder: big/flo (fractional)"277 (receive (quotient&remainder b1 0.5)))278)279280(test-group "gcd"281 (test-equal "gcd: fix (64-bit)/big" (gcd 907947775416515 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111) 1)282 (test-equal "gcd: big/big" (gcd 234897235923342343242 234790237101762305340234) 6)283 (test-equal (gcd) 0)284 (test-equal (gcd 6) 6)285 (test-equal (gcd -2) 2)286 (test-equal (gcd 6 8) 2)287 (test-equal (gcd 6 8 5) 1)288 (test-equal (gcd 6 -8 5) 1)289 (test-equal (gcd 6.0) 6.0)290 (test-equal (gcd 6.0 8.0) 2.0)291 (test-error (gcd 6.1))292 (test-error (gcd 6.1 8.0))293 (test-error (gcd 6.0 8.1))294 (test-error (gcd +inf.0))295 (test-error (gcd +nan.0))296 (test-error (gcd 6.0 +inf.0))297 (test-error (gcd +inf.0 6.0))298 (test-error (gcd +nan.0 6.0))299 (test-error (gcd 6.0 +nan.0))300 (test-error (gcd 1+2i 3+4i))301 (test-error (gcd 1/2 3/4)))302303(test-group "lcm"304 (test-equal (lcm) 1)305 (test-equal (lcm 5) 5)306 (test-equal (lcm -8) 8)307 (test-equal (lcm 6 8) 24)308 (test-equal (lcm 6 8 5) 120)309 (test-equal (lcm 6.0 8.0) 24.0)310 (test-error (lcm 6.1 8.0))311 (test-error (lcm 6.0 8.1))312 (test-error (lcm +inf.0))313 (test-error (lcm +nan.0))314 (test-error (lcm 6.0 +inf.0))315 (test-error (lcm +inf.0 6.0))316 (test-error (lcm +nan.0 6.0))317 (test-error (lcm 6.0 +nan.0))318 (test-error (lcm 1+2i 3+4i))319 (test-error (lcm 1/2 3/4)))320321322(test-group "equality"323324 (test-equal "=: fix/fix" (= 33 33) #t)325 (test-equal "=: fix/flo" (= 33 33.0) #t)326 (test-equal "=: !fix/fix" (= 33 34) #f)327 (test-equal "=: !fix/flo" (= 33 33.1) #f)328 (test-equal "=: !fix/flo (overflow)" (= 9007199254740993 9007199254740992.0) #f)329 (test-equal "=: !fix/flo (inf)" (= 0 +inf.0) #f)330 (test-equal "=: !fix/flo (-inf)" (= 0 -inf.0) #f)331 (test-equal "=: !fix/flo (+nan)" (= 0 -nan.0) #f)332 (test-equal "=: flo/fix" (= 33.0 33) #t)333 (test-equal "=: !flo/fix (overflow)" (= 9007199254740992.0 9007199254740993) #f)334 (test-equal "=: !flo/fix (inf)" (= +inf.0 0) #f)335 (test-equal "=: !flo/fix (-inf)" (= -inf.0 0) #f)336 (test-equal "=: !flo/fix (+nan)" (= -nan.0 0) #f)337 (test-equal "=: flo/flo" (= 33.1 33.1) #t)338 (test-equal "=: !flo/flo" (= 33.1 -33.1) #f)339 ;; Flonums are only 53 bits of precision, so it will drop data.340 ;; Comparison is exact341 (unless 64-bits?342 (test-equal "=: big/flo" (= b1 (+ 0.0 b1)) #t))343 (test-equal "=: big/big" (= b1 b1) #t)344 (test-equal "=: !big/big" (= b2 b1) #f)345 (test-equal "=: rat/flo" (= r1 (+ r1 0.0)) #t)346 (test-equal "=: rat/rat" (= r1 r1) #t)347 (test-equal "=: !rat/rat" (= r1 r2) #f)348 (test-equal "=: comp/comp" (= c1 c1) #t)349 (test-equal "=: !comp/comp" (= c1 c2) #f)350)351352(test-group "generic equality"353 (test-equal "equal?: fix/fix" (equal? 33 33) #t)354 (test-equal "equal?: fix/flo" (equal? 33 33.0) #f)355 (test-equal "equal?: !fix/fix" (equal? 33 34) #f)356 (test-equal "equal?: !fix/flo" (equal? 33 33.1) #f)357 (test-equal "equal?: flo/fix" (equal? 33.0 33) #f)358 (test-equal "equal?: flo/flo" (equal? 33.1 33.1) #t)359 (test-equal "equal?: !flo/flo" (equal? 33.1 -33.1) #f)360 (test-equal "equal?: big/flo" (equal? b1 (+ 0.0 b1)) #f)361 (test-equal "equal?: big/big" (equal? b1 b1) #t)362 (test-equal "equal?: big/big2" (equal? b1 (+ 1 b1 -1)) #t)363 (test-equal "equal?: !big/big" (equal? b2 b1) #f)364 (test-equal "equal?: rat/flo" (equal? r1 (+ r1 0.0)) #f)365 (test-equal "equal?: rat/rat" (equal? r1 r1) #t)366 (test-equal "equal?: !rat/rat" (equal? r1 r2) #f)367 (test-equal "equal?: comp/comp" (equal? c1 c1) #t)368 (test-equal "equal?: !comp/comp" (equal? c1 c2) #f)369 (test-equal "equal?: nan/nan" (equal? (/ 0.0 0.0) (/ 0.0 0.0)) #f)370 (test-equal "equal?: nan+nan/nan+nan" (equal? (make-rectangular (/ 0.0 0.0)371 (/ 0.0 0.0))372 (make-rectangular (/ 0.0 0.0)373 (/ 0.0 0.0))) #f)374)375376377(test-group "greater & greater/equal"378379 (test-equal ">: fix/fix" (> 44 33) #t)380 (test-equal ">=: fix/fix" (>= 44 33) #t)381 (test-equal ">: fix/fix/fix" (> 44 33 22) #t)382 (test-equal ">=: fix/fix/fix" (>= 44 33 22) #t)383 (test-equal ">: !fix/fix" (> 33 44) #f)384 (test-equal ">=: !fix/fix" (>= 33 44) #f)385 (test-equal ">: !fix/fix/fix" (> 22 33 44) #f)386 (test-equal ">=: !fix/fix/fix" (>= 22 33 44) #f)387 (test-equal ">: fix/fix" (> 33 33) #f)388 (test-equal ">=: !fix/fix" (>= 33 33) #t)389 (test-equal ">: fix/flo" (> 44 33.0) #t)390 (test-equal ">=: fix/flo" (>= 44 33.0) #t)391 (test-equal ">: !fix/flo" (> 33 44.0) #f)392 (test-equal ">=: !fix/flo" (>= 33 44.0) #f)393 (test-equal ">: !fix/flo" (> 33 33.0) #f)394 (test-equal ">=: !fix/flo" (>= 33 33.0) #t)395 (test-equal ">: fix/flo (flo overflow), on 64 bits"396 (> 9007199254740993 9007199254740992.0) #t) ; 2^53397 (test-equal ">=: fix/flo (flo overflow), on 64 bits"398 (>= 9007199254740993 9007199254740992.0) #t)399 (test-equal ">: fix/flo (flo underflow), on 64 bits"400 (> -9007199254740992 -9007199254740991.0) #f)401 (test-equal ">=: fix/flo (flo underflow), on 64 bits"402 (>= -9007199254740992 -9007199254740991.0) #f)403 (test-equal ">: fix/big" (> 44 b2) #t)404 (test-equal ">=: fix/big" (>= 44 b2) #t)405 (test-equal ">: !fix/big" (> 33 b1) #f)406 (test-equal ">=: !fix/big" (>= 33 b1) #f)407 (test-equal ">: fix/rat" (> 44 r1) #t)408 (test-equal ">=: fix/rat" (>= 44 r1) #t)409 (test-equal ">: !fix/rat" (> 0 r1) #f)410 (test-equal ">=: !fix/rat" (>= 0 r1) #f)411412 (test-equal ">: flo/fix" (> 44.0 33) #t)413 (test-equal ">=: flo/fix" (>= 44.0 33) #t)414 (test-equal ">: !flo/fix" (> 33.0 44) #f)415 (test-equal ">=: !flo/fix" (>= 33.0 44) #f)416 (test-equal ">: !flo/fix" (> 33.0 33) #f)417 (test-equal ">=: flo/fix" (>= 33.0 33) #t)418 (test-equal ">: flo/flo" (> 44.0 33.0) #t)419 (test-equal ">=: flo/flo" (>= 44.0 33.0) #t)420 (test-equal ">: !flo/flo" (> 33.0 44.0) #f)421 (test-equal ">=: !flo/flo" (>= 33.0 44.0) #f)422 (test-equal ">: flo/big" (> 44.0 b2) #t)423 (test-equal ">=: flo/big" (>= 44.0 b2) #t)424 (test-equal ">: flo/fix (flo overflow), on 64 bits"425 (> 9007199254740992.0 9007199254740993) #f) ; 2^53426 (test-equal ">=: flo/fix (flo overflow), on 64 bits"427 (>= 9007199254740992.0 9007199254740993) #f)428 (test-equal ">: fix/flo (flo underflow), on 64 bits"429 (> -9007199254740991.0 -9007199254740992) #t)430 (test-equal ">=: fix/flo (flo underflow), on 64 bits"431 (>= -9007199254740991.0 -9007199254740992) #t)432 (test-equal ">: flo/big (flo overflow)"433 (> 1237940039285380274899124224.0 1237940039285380274899124225) #f)434 (test-equal ">=: flo/big (flo overflow)"435 (>= 1237940039285380274899124224.0 1237940039285380274899124225) #f)436 (test-equal ">: !flo/big" (> 33.0 b1) #f)437 (test-equal ">=: !flo/big" (>= 33.0 b1) #f)438 (test-equal ">: flo/rat" (> 44.0 r1) #t)439 (test-equal ">=: flo/rat" (>= 44.0 r1) #t)440 (test-equal ">: !flo/rat" (> 0.0 r1) #f)441 (test-equal ">=: !flo/rat" (>= 0.0 r1) #f)442 (test-equal ">: !rat/rat" (> r1 r1) #f)443 (test-equal ">=: rat/rat" (>= r1 r1) #t)444 (test-equal ">: flo/nan" (> 0.0 +nan.0) #f)445 (test-equal ">=: flo/nan" (>= 0.0 +nan.0) #f)446 (test-equal ">: nan/flo" (> +nan.0 0.0) #f)447 (test-equal ">=: nan/flo" (>= +nan.0 0.0) #f)448 (test-equal ">: flo/flo/nan" (> 1.0 0.0 +nan.0) #f)449 (test-equal ">=: flo/flo/nan" (>= 1.0 0.0 +nan.0) #f)450451 (test-equal ">: big/fix" (> b1 33) #t)452 (test-equal ">=: big/fix" (>= b1 33) #t)453 (test-equal ">: !big/fix" (> b2 44) #f)454 (test-equal ">=: !big/fix" (>= b2 44) #f)455 (test-equal ">: big/flo" (> b1 33.0) #t)456 (test-equal ">=: big/flo" (>= b1 33.0) #t)457 (test-equal ">: big/flo (flo overflow)"458 (> 1237940039285380274899124225 1237940039285380274899124224.0) #t)459 (test-equal ">=: big/flo (flo overflow)"460 (>= 1237940039285380274899124225 1237940039285380274899124224.0) #t)461 (test-equal ">: !big/flo" (> b2 44.0) #f)462 (test-equal ">=: !big/flo" (>= b2 44.0) #f)463 (test-equal ">: big/big" (> b1 b2) #t)464 (test-equal ">=: big/big" (>= b1 b2) #t)465 (test-equal ">: !big/big" (> b2 b1) #f)466 (test-equal ">=: !big/big" (>= b2 b1) #f)467 (test-equal ">: big/rat" (> b1 r1) #t)468 (test-equal ">=: big/rat" (>= b1 r1) #t)469 (test-equal ">: !big/rat" (> b2 r1) #f)470 (test-equal ">=: !big/rat" (>= b2 r1) #f)471472 (test-equal ">: rat/fix" (> r1 2) #f)473 (test-equal ">=: rat/fix" (>= r1 2) #f)474 (test-equal ">: !rat/fix" (> r1 44) #f)475 (test-equal ">=: !rat/fix" (>= r1 44) #f)476 (test-equal ">: rat/flo" (> r2 2.0) #t)477 (test-equal ">=: rat/flo" (>= r2 2.0) #t)478 (test-equal ">: !rat/flo" (> b2 44.0) #f)479 (test-equal ">=: !rat/flo" (>= b2 44.0) #f)480 (test-equal ">: !rat/big" (> r1 b1) #f)481 (test-equal ">=: !rat/big" (>= r1 b1) #f)482 (test-equal ">: rat/rat" (> r2 r1) #t)483 (test-equal ">=: rat/rat" (>= r2 r1) #t)484 (test-equal ">: !rat/rat" (> r1 r2) #f)485 (test-equal ">=: !rat/rat" (>= r1 r2) #f)486 (test-equal ">: rat/flo (flo overflow)"487 (> 1237940039285380274899124224/1237940039285380274899124223 1.0) #t)488 (test-equal ">: rat/flo (flo overflow)"489 (> 1237940039285380274899124224/1237940039285380274899124223 1.5) #f)490 (test-equal ">=: rat/flo (flo overflow)"491 (>= 1237940039285380274899124224/1237940039285380274899124223 1.0) #t)492 (test-equal ">=: rat/flo (flo overflow)"493 (>= 1237940039285380274899124224/1237940039285380274899124223 1.5) #f)494 (test-equal ">: rat/flo (flo underflow)"495 (> -1237940039285380274899124224/1237940039285380274899124223 -1.0) #f)496 (test-equal ">: rat/flo (flo underflow)"497 (> -1237940039285380274899124224/1237940039285380274899124223 -1.5) #t)498 (test-equal ">=: rat/flo (flo underflow)"499 (>= -1237940039285380274899124224/1237940039285380274899124223 -1.0) #f)500 (test-equal ">=: rat/flo (flo underflow)"501 (>= -1237940039285380274899124224/1237940039285380274899124223 -1.5) #t)502)503504505(test-group "less & less/equal"506507 (test-equal "<: !fix/fix" (< 44 33) #f)508 (test-equal "<=: !fix/fix" (<= 44 33) #f)509 (test-equal "<: fix/fix/fix" (< 33 44 55) #t)510 (test-equal "<=: fix/fix/fix" (<= 33 44 55) #t)511 (test-equal "<: !fix/fix/fix" (< 33 55 44) #f)512 (test-equal "<=: !fix/fix/fix" (<= 33 55 44) #f)513 (test-equal "<: !fix/fix/fix" (< 44 33 55) #f)514 (test-equal "<=: !fix/fix/fix" (<= 44 33 55) #f)515 (test-equal "<: !fix/fix/fix" (< 44 44 44) #f)516 (test-equal "<=: fix/fix/fix" (<= 44 44 44) #t)517 (test-equal "<: fix/fix" (< 33 44) #t)518 (test-equal "<=: fix/fix" (<= 33 44) #t)519 (test-equal "<: !fix/fix" (< 33 33) #f)520 (test-equal "<=: fix/fix" (<= 33 33) #t)521 (test-equal "<: !fix/flo" (< 44 33.0) #f)522 (test-equal "<=: !fix/flo" (<= 44 33.0) #f)523 (test-equal "<: fix/flo" (< 33 44.0) #t)524 (test-equal "<=: fix/flo" (<= 33 44.0) #t)525 (test-equal "<: fix/flo (flo overflow), on 64 bits"526 (< 9007199254740993 9007199254740992.0) #f) ; 2^53527 (test-equal "<=: fix/flo (flo overflow), on 64 bits"528 (< 9007199254740993 9007199254740992.0) #f)529 (test-equal "<: fix/flo (flo underflow), on 64 bits"530 (< -9007199254740993 -9007199254740992.0) #t)531 (test-equal "<=: fix/flo (flo underflow), on 64 bits"532 (<= -9007199254740993 -9007199254740992.0) #t)533 (test-equal "<: !fix/flo" (< 33.0 33.0) #f)534 (test-equal "<=: fix/flo" (<= 33.0 33.0) #t)535 (test-equal "<: !fix/big" (< 44 b2) #f)536 (test-equal "<=: !fix/big" (<= 44 b2) #f)537 (test-equal "<: fix/big" (< 33 b1) #t)538 (test-equal "<=: fix/big" (<= 33 b1) #t)539 (test-equal "<: !big/big" (< b1 b1) #f)540 (test-equal "<=: big/big" (<= b1 b1) #t)541 (test-equal "<: !fix/rat" (< 44 r1) #f)542 (test-equal "<=: !fix/rat" (<= 44 r1) #f)543 (test-equal "<: fix/rat" (< 0 r1) #t)544 (test-equal "<=: fix/rat" (<= 0 r1) #t)545546 (test-equal "<: !flo/fix" (< 44.0 33) #f)547 (test-equal "<=: !flo/fix" (<= 44.0 33) #f)548 (test-equal "<: flo/fix" (< 33.0 44) #t)549 (test-equal "<=: flo/fix" (<= 33.0 44) #t)550 (test-equal "<: !flo/flo" (< 44.0 33.0) #f)551 (test-equal "<=: !flo/flo" (<= 44.0 33.0) #f)552 (test-equal "<: flo/flo" (< 33.0 44.0) #t)553 (test-equal "<=: flo/flo" (<= 33.0 44.0) #t)554 (test-equal "<: !flo/big" (< 44.0 b2) #f)555 (test-equal "<=: !flo/big" (<= 44.0 b2) #f)556 (test-equal "<: flo/big" (< 33.0 b1) #t)557 (test-equal "<=: flo/big" (<= 33.0 b1) #t)558 (test-equal "<: flo/fix (flo overflow), on 64 bits"559 (< 9007199254740992.0 9007199254740993) #t) ; 2^53560 (test-equal "<=: flo/fix (flo overflow), on 64 bits"561 (< 9007199254740992.0 9007199254740993) #t)562 (test-equal "<: flo/fix (flo underflow), on 64 bits"563 (< -9007199254740992.0 -9007199254740993) #f)564 (test-equal "<=: flo/fix (flo underflow), on 64 bits"565 (<= -9007199254740992.0 -9007199254740993) #f)566 (test-equal "<: flo/big (flo overflow)"567 (< 1237940039285380274899124224.0 1237940039285380274899124225) #t)568 (test-equal "<=: flo/big (flo overflow)"569 (<= 1237940039285380274899124224.0 1237940039285380274899124225) #t)570 (test-equal "<: !flo/rat" (< 44.0 r1) #f)571 (test-equal "<=: !flo/rat" (<= 44.0 r1) #f)572 (test-equal "<: flo/rat" (< 0.0 r1) #t)573 (test-equal "<=: flo/rat" (<= 0.0 r1) #t)574 (test-equal "<: flo/nan" (< 0.0 +nan.0) #f)575 (test-equal "<=: flo/nan" (<= 0.0 +nan.0) #f)576 (test-equal "<: nan/flo" (< +nan.0 0.0) #f)577 (test-equal "<=: nan/flo" (<= +nan.0 0.0) #f)578 (test-equal "<: flo/flo/nan" (< 0.0 1.0 +nan.0) #f)579 (test-equal "<=: flo/flo/nan" (<= 0.0 1.0 +nan.0) #f)580581 (test-equal "<: !big/fix" (< b1 33) #f)582 (test-equal "<=: !big/fix" (<= b1 33) #f)583 (test-equal "<: big/fix" (< b2 44) #t)584 (test-equal "<=: big/fix" (<= b2 44) #t)585 (test-equal "<: !big/flo" (< b1 33.0) #f)586 (test-equal "<=: !big/flo" (<= b1 33.0) #f)587 (test-equal "<: big/flo" (< b2 44.0) #t)588 (test-equal "<=: big/flo" (<= b2 44.0) #t)589 (test-equal "<: big/flo (max flo)"590 (< 1237940039285380274899124224 1237940039285380274899124224.0) #f)591 (test-equal "<=: big/flo (max flo)"592 (<= 1237940039285380274899124224 1237940039285380274899124224.0) #t)593 (test-equal "<: big/flo (max flo, smaller bignum)"594 (< 1237940039285380274899124223 1237940039285380274899124224.0) #t)595 (test-equal "<: big/flo (max flo, smaller bignum)"596 (<= 1237940039285380274899124223 1237940039285380274899124224.0) #t)597 (test-equal "<: !big/big" (< b1 b2) #f)598 (test-equal "<=: !big/big" (<= b1 b2) #f)599 (test-equal "<: big/big" (< b2 b1) #t)600 (test-equal "<=: big/big" (<= b2 b1) #t)601 (test-equal "<: !big/rat" (< b1 r1) #f)602 (test-equal "<=: !big/rat" (<= b1 r1) #f)603 (test-equal "<: big/rat" (< b2 r1) #t)604 (test-equal "<=: big/rat" (<= b2 r1) #t)605606 (test-equal "<: !rat/fix" (< r2 2) #f)607 (test-equal "<=: !rat/fix" (<= r2 2) #f)608 (test-equal "<: rat/fix" (< r1 44) #t)609 (test-equal "<=: rat/fix" (<= r1 44) #t)610 (test-equal "<: !rat/flo" (< r2 2.0) #f)611 (test-equal "<=: !rat/flo" (<= r2 2.0) #f)612 (test-equal "<: rat/flo" (< b2 44.0) #t)613 (test-equal "<=: rat/flo" (<= b2 44.0) #t)614 (test-equal "<: rat/big" (< r1 b1) #t)615 (test-equal "<=: rat/big" (<= r1 b1) #t)616 (test-equal "<: !rat/rat" (< r2 r1) #f)617 (test-equal "<=: !rat/rat" (<= r2 r1) #f)618 (test-equal "<: rat/rat" (< r1 r2) #t)619 (test-equal "<=: rat/rat" (<= r1 r2) #t)620 (test-equal "<: rat/flo (flo overflow)"621 (< 1237940039285380274899124224/1237940039285380274899124223 1.0) #f)622 (test-equal "<: rat/flo (flo overflow)"623 (< 1237940039285380274899124224/1237940039285380274899124223 1.5) #t)624 (test-equal "<=: rat/flo (flo overflow)"625 (<= 1237940039285380274899124224/1237940039285380274899124223 1.0) #f)626 (test-equal "<=: rat/flo (flo overflow)"627 (<= 1237940039285380274899124224/1237940039285380274899124223 1.5) #t)628 (test-equal "<: rat/flo (flo underflow)"629 (< -1237940039285380274899124224/1237940039285380274899124223 -1.0) #t)630 (test-equal "<: rat/flo (flo underflow)"631 (< -1237940039285380274899124224/1237940039285380274899124223 -1.5) #f)632 (test-equal "<=: rat/flo (flo underflow)"633 (<= -1237940039285380274899124224/1237940039285380274899124223 -1.0) #t)634 (test-equal "<=: rat/flo (flo underflow)"635 (<= -1237940039285380274899124224/1237940039285380274899124223 -1.5) #f)636)637638(test-group "complex"639640 (test-equal "real-part" (real-part c1) 33)641 (test-equal "real-part of flonum" (real-part 1.23) 1.23)642 (test-equal "real-part of fixnum" (real-part 123) 123)643 (test-equal "real-part of ratnum" (real-part 1/2) 1/2)644 (test-equal "real-part of bignum" (real-part b1) b1)645 (test-equal "real-part of negative flonum" (real-part -1.23) -1.23)646 (test-equal "real-part of negative fixnum" (real-part -123) -123)647 (test-equal "real-part of negative ratnum" (real-part -1/2) -1/2)648 (test-equal "real-part of negative bignum" (real-part (- b1)) (- b1))649 (test-equal "imag-part" (imag-part c1) 44)650 (test-equal "imag-part of flonum" (imag-part 1.23) 0.0)651 (test-equal "imag-part of fixnum" (imag-part 123) 0)652 (test-equal "imag-part of ratnum" (imag-part 1/2) 0)653 (test-equal "imag-part of bignum" (imag-part b1) 0)654 (test-assert "make-polar" (show (make-polar 33 44)))655 (test-equal "magnitude" (magnitude 0+8i) 8)656 (test-equal "magnitude" (magnitude 0+1/2i) 1/2)657 (test-equal "magnitude of flonum" (magnitude 1.23) 1.23)658 (test-equal "magnitude of fixnum" (magnitude 123) 123)659 (test-equal "magnitude of ratnum" (magnitude 1/2) 1/2)660 (test-equal "magnitude of bignum" (magnitude b1) b1)661 (test-equal "magnitude of negative flonum" (magnitude -1.23) 1.23)662 (test-equal "magnitude of negative fixnum" (magnitude -123) 123)663 (test-equal "magnitude of negative ratnum" (magnitude -1/2) 1/2)664 (test-equal "magnitude of negative bignum" (magnitude (- b1)) b1)665 (test-assert "angle" (show (angle c1)))666 (test-equal "angle of flonum" (angle 1.23) 0.0)667 (test-equal "angle of fixnum" (angle 123) 0.0)668 (test-equal "angle of ratnum" (angle 1/2) 0.0)669 (test-equal "angle of bignum" (angle b1) 0.0)670 (test-equal "angle of negative flonum" (angle -1.23) pi)671 (test-equal "angle of negative fixnum" (angle -123) pi)672 (test-equal "angle of negative ratnum" (angle -1/2) pi)673 (test-equal "angle of negative bignum" (angle (- b1)) pi)674)675676(test-group "rational"677678 ;; Use equal? instead of = to check equality and exactness in one go679 (parameterize ((current-test-comparator equal?))680 (test-assert (show (numerator b1)))681 (test-equal (numerator r1) 3)682 (test-equal (numerator 33) 33)683 (test-equal (denominator r1) 4)684 (test-equal (denominator b1) 1)685 (test-equal (denominator 33) 1)686 (test-equal (numerator 0) 0)687 (test-equal (denominator 0) 1)688 (test-equal (numerator 3) 3)689 (test-equal (denominator 3) 1)690 (test-equal (numerator -3) -3)691 (test-equal (denominator -3) 1)692 (test-equal (numerator 0.5) 1.0)693 (test-equal (denominator 0.5) 2.0)694 (test-equal (numerator 1.25) 5.0)695 (test-equal (denominator 1.25) 4.0)696 (test-equal (numerator -1.25) -5.0)697 (test-equal (denominator -1.25) 4.0)698 (test-equal (numerator 1e10) 1e10)699 (test-equal (denominator 1e10) 1.0))700 (test-error (numerator +inf.0))701 (test-error (numerator +nan.0))702 (test-error (denominator +inf.0))703 (test-error (denominator +nan.0))704705)706707(test-group "misc"708709 (test-equal "inexact->exact" (inexact->exact 2.3) 2589569785738035/1125899906842624)710 (test-error "inexact->exact +inf" (inexact->exact +inf.0))711 (test-error "inexact->exact -inf" (inexact->exact -inf.0))712 (test-error "inexact->exact -NaN" (inexact->exact +nan.0))713 (test-equal "sqrt (integer result)" (sqrt 16) 4)714 (test-equal "sqrt (exact result)" (sqrt 1/4) 1/2)715 (parameterize ((current-test-epsilon 1e-10))716 (test-equal "sqrt (inexact result)" (sqrt 2) 1.4142135623730951))717 (test-equal "sqrt (inexact input)" (sqrt 4.0) 2.0)718 (test-equal "sqrt (exact large number)" (sqrt (* max-fix max-fix)) max-fix)719 (test-error "exact-integer-sqrt (nonint flonum)" (exact-integer-sqrt 1.5))720 (test-error "exact-integer-sqrt (ratnum)" (exact-integer-sqrt 1/2))721 (test-error "exact-integer-sqrt (int flonum)" (exact-integer-sqrt 4.0))722 (test-equal "exact-integer-sqrt (w/o rest)"723 (receive x (exact-integer-sqrt (* max-fix max-fix)) x)724 (list max-fix 0))725 (test-equal "exact-integer-sqrt (with rest)"726 (receive x (exact-integer-sqrt (+ (* max-fix max-fix) 5)) x)727 (list max-fix 5))728 (test-equal "exact-integer-nth-root without rest"729 (receive x (exact-integer-nth-root 243 5) x)730 (list 3 0))731 (test-equal "exact-integer-nth-root with rest"732 (receive x (exact-integer-nth-root 128 4) x)733 (list 3 47))734 (test-equal "exact-integer-nth-root with insanely large base"735 (receive x (exact-integer-nth-root 5 (if 64-bits? 10000000000 100000000)) x)736 (list 1 4))737 (test-equal "expt" (expt 2 4) 16)738 (test-assert "expt" (show (expt 2 100)))739 ;; The next three according to R7RS740 (test-equal "expt 0.0^0.0)" (expt 0.0 0.0) 1.0)741 (test-equal "expt 0.0^{pos}" (expt 0.0 1.0) 0.0)742 ;; An error is not mandatory:743 ;; "[...] either an error is signalled or an unspecified number is returned."744 ;(test-error "expt 0.0^{neg}" (expt 0.0 -1.0))745 ;; R7 doesn't say anything specific about fixnums, so I guess this should behave the same746 (test-equal "expt 0^0" (expt 0 0) 1)747 (test-equal "expt 0^{pos}" (expt 0 1) 0)748 (test-error "expt 0^{neg}" (expt 0 -1))749 (test-equal "expt (rat base)" (expt 1/2 2) 1/4)750 (test-equal "expt (rat exponent)" (expt 16 1/4) 2)751 (test-equal "expt (negative rat exponent)" (expt 16 -1/4) 1/2)752 (test-equal "expt (inexact from rat exponent)" (expt 2 1/7) 1.1040895136738123)753 (test-equal "expt (> 1 rat exponent)" (expt 1/64 3/2) 1/512)754 (test-equal "expt (rat base & exponent)" (expt 1/4 1/2) 1/2)755 (parameterize ((current-test-epsilon 1e-10))756 (test-equal "expt (negative w/ rat exponent)" (expt -16 1/4) 1.4142135623731+1.41421356237309i))757 (test-assert "expt" (show (expt 2 2.0)))758 (test-assert "expt" (show (expt 2 -1)))759 (test-equal "expt between double and 64-bit integer value"760 (expt 999 6) 994014980014994001)761 (parameterize ((current-test-epsilon 1e-10))762 (test-equal "expt with complex result" (expt -1 1.5) -1.836909530733566e-16-1.0i))763 (test-equal "exact expt with complex number" (expt 0+1i 5) 0+1i)764 (test-equal "exact expt with complex number, real result" (expt 0+1i 6) -1)765 (test-equal "inexact expt with complex number" (expt 0.0+1.0i 5.0) 0.0+1.0i)766 (test-equal "inexact expt with complex number, real result" (expt 0.0+1.0i 6.0) -1.0)767 (parameterize ((current-test-epsilon 1e-10))768 (test-equal "inexact noninteger expt with complex number"769 (expt 0.0+4.0i 0.5) 1.4142135623731+1.41421356237309i)770 (test-equal "exp with complex numbers" (exp 1+i) 1.4686939399158851+2.2873552871788423i))771772 (test-equal "log of exp = 1" (log (exp 1)) 1.0)773 (test-assert "log(-x) = compnum" (cplxnum? (log -2.0)))774 (parameterize ((current-test-epsilon 1e-10))775 (test-equal "log of -1" (log -1) 0.0+3.141592653589793i))776 ;; XXX We should probably attempt to make this return an exact number777 (parameterize ((current-test-epsilon 1e-10))778 (test-equal "log(expt(2,x),2) = x" (log (expt 2 500) 2) 500.0)779 (test-equal "log with complex number" (log +i) 0.0+1.5707963267948966i)780781 (test-equal "exp(log(x)) = x" (exp (log 2.0-3.0i)) 2.0-3.0i)782 (test-equal "log(exp(x)) = x" (log (exp 2.0-3.0i)) 2.0-3.0i)783 (test-equal "log(expt(2,x),2) = x" (log (expt 2 2.0-3.0i) 2) 2.0-3.0i))784785 (letrec ((fac (lambda (n)786 (if (zero? n)787 1788 (* n (fac (- n 1))) ) ) ) )789 (test-assert "bigfac" (show (fac 100)))790 (test-equal "zero signum fixnum" (signum 0) 0)791 (test-equal "zero signum flonum" (signum .0) 0.0)792 (test-equal "positive signum fixnum" (signum 2) 1)793 (test-equal "positive signum ratnum" (signum 1/2) 1)794 (test-equal "positive signum flonum" (signum 2.0) 1.0)795 (test-equal "positive signum bignum" (signum b1) 1)796 (test-equal "negative signum fixnum" (signum -2) -1)797 (test-equal "negative signum ratnum" (signum -1/2) -1)798 (test-equal "negative signum flonum" (signum -2) -1)799 (test-equal "negative signum bignum" (signum (- b1)) -1)800 ;; From CLHS801 (parameterize ((current-test-epsilon 1e-10))802 (test-equal "positive signum compnum(1)" (signum 0+33i) 0+1i)803 (test-equal "positive signum compnum(2)" (signum 7.5+10.0i) 0.6+0.8i)804 (test-equal "negative signum compnum " (signum 0.0-14.7i) 0.0-1.0i)))805 (test-equal "most-negative-fixnum + most-negative-fixnum = 2 * most-negative-fixnum"806 (+ most-negative-fixnum most-negative-fixnum) (* 2 most-negative-fixnum))807 (test-equal "most-negative-fixnum - most-negative-fixnum = 0"808 (- most-negative-fixnum most-negative-fixnum) 0)809 (test-equal "most-positive-fixnum + most-positive-fixnum = 2 * most-positive-fixnum"810 (+ most-positive-fixnum most-positive-fixnum) (* 2 most-positive-fixnum))811 (test-equal "most-positive-fixnum - most-positive-fixnum = 0"812 (- most-positive-fixnum most-positive-fixnum) 0)813)814815816(test-group "R5RS"817818 (test-equal "+" (+ 3 4) 7)819 (test-equal "+" (+ 3) 3)820 (test-equal "+" (+) 0)821 (test-equal "*" (* 4) 4)822 (test-equal "*" (*) 1)823824 (test-equal "-" (- 3 4) -1)825 (test-equal "-" (- 3 4 5) -6)826 (test-equal "-" (- 3) -3)827 (test-assert "/ (3/20)" (show (/ 3 4 5)))828 (test-assert "/ (1/3)" (show (/ 3)))829830 (test-equal "numerator" (numerator (/ 6 4)) 3)831 (test-equal "denominator" (denominator (/ 6 4)) 2)832833 (test-equal "complex?" (complex? c1) #t)834 (test-equal "complex?" (complex? 3) #t)835 (test-equal "real?" (real? 3) #t)836 (test-equal "real?" (real? (make-rectangular -2.5 0.0)) #t)837 (test-equal "real?" (real? -2+1i) #f)838 (test-equal "real?" (real? 1e0) #t)839 (test-equal "rational?" (rational? (/ 6 10)) #t)840 (test-assert "check rational" (show (/ 6 3)))841 (test-equal "rational?" (rational? (/ 6 3)) #t)842 (test-equal "integer?" (integer? (make-rectangular 3 0)) #t)843 (test-equal "integer?" (integer? 1+3i) #f)844 (test-equal "integer?" (integer? 3.0) #t)845 (test-equal "integer?" (integer? (/ 8 4)) #t)846 (test-equal "integer?" (integer? 1/2) #f)847 (test-equal "exact-integer?" (exact-integer? (make-rectangular 3 0)) #t)848 (test-equal "exact-integer?" (exact-integer? 1+3i) #f)849 (test-equal "exact-integer?" (exact-integer? 3.0) #f)850 (test-equal "exact-integer?" (exact-integer? (/ 8 4)) #t)851 (test-equal "exact-integer?" (exact-integer? 1/2) #f)852853 (test-equal "max" (max 3 4) 4)854 (test-equal "max" (max 3.9 4) 4.0)855856 (test-equal "modulo" (modulo 13 4) 1)857 (test-equal "modulo" (modulo 13.0 4) 1.0)858 (test-equal "modulo" (modulo 13 4.0) 1.0)859 (test-error "modulo" (modulo 13.1 4.0))860 (test-error "modulo" (modulo 13.0 4.1))861 (test-equal "remainder" (remainder 13 4) 1)862 (test-error "remainder" (remainder 13.1 4.0))863 (test-error "remainder" (remainder 13.0 4.1))864 (test-equal "modulo" (modulo -13 4) 3)865 (test-equal "remainder" (remainder -13 4) -1)866 (test-equal "modulo" (modulo 13 -4) -3)867 (test-equal "remainder" (remainder 13 -4) 1)868 (test-equal "modulo" (modulo -13 -4) -1)869 (test-equal "remainder" (remainder -13 -4) -1)870 (test-equal "remainder" (remainder -13 -4.0) -1.0)871872 (test-assert (even? 2))873 (test-assert (not (even? 1)))874 (test-assert (even? -2))875 (test-assert (not (even? -1)))876 (test-assert (even? 2.0))877 (test-assert (not (even? 1.0)))878 (test-assert (even? -2.0))879 (test-assert (not (even? -1.0)))880 (test-error (even? 2.1))881 (test-error (even? -2.3))882 (test-error (even? +inf.0))883 (test-error (even? +nan.0))884 (test-assert (even? (* most-positive-fixnum 2)))885 (test-assert (not (even? (+ (* most-positive-fixnum 2) 1))))886 (test-assert (odd? (+ (* most-positive-fixnum 2) 1)))887 (test-assert (not (odd? (* most-positive-fixnum 2))))888 (test-error (even? 2.0+3.0i))889 (test-error (even? 2+3i))890 (test-error (odd? 2.0+3.0i))891 (test-error (odd? 2+3i))892893 (test-equal "floor" (floor -4.3) -5.0)894 (test-equal "ceiling" (ceiling -4.3) -4.0)895 (test-equal "truncate" (truncate -4.3) -4.0)896 (test-equal "round" (round -4.3) -4.0)897 (test-equal "floor" (floor 3.5) 3.0)898 (test-equal "ceiling" (ceiling 3.5) 4.0)899 (test-equal "truncate" (truncate 3.5) 3.0)900 (test-equal "round" (round 3.5) 4.0)901 (test-equal "round" (round 4.5) 4.0)902 (test-equal "round" (round (/ 7 2)) 4)903 (test-equal "round" (round 7) 7)904905 (test-equal "rationalize (1/3)" (rationalize (inexact->exact .3) (/ 1 10)) 1/3)906 (test-equal "rationalize (#i1/3)" (rationalize .3 (/ 1 10)) #i1/3)907)908909(test-group "bitwise ops"910911 (test-equal "and" (bitwise-and #xff #x1) 1)912 (test-equal "zero-arg and" (bitwise-and) -1) ; Arbitrary, but specified by srfi-33913 (test-equal "ior" (bitwise-ior #x0f #x1) #xf)914 (test-equal "zero-arg ior" (bitwise-ior) 0) ; Same915 (test-equal "xor" (bitwise-xor #x0f #x1) 14)916 (test-equal "zero-arg xor" (bitwise-xor) 0) ; Same917 (test-assert "not" (show (bitwise-not #x0f)))918 (test-error (bitwise-and 'x))919 (test-error (bitwise-xor 'x))920 (test-error (bitwise-ior 'x))921 (test-error (bitwise-and 1 'x))922 (test-error (bitwise-xor 1 'x))923 (test-error (bitwise-ior 1 'x))924 (test-error (bit->boolean 1 -1))925 (test-error (bit->boolean b1 -1))926 (test-error (bit->boolean 1 1.0))927 (test-error (bit->boolean 1.0 1))928 (test-equal (bit->boolean -1 b1) #t)929 (test-equal (bit->boolean 0 b1) #f)930 (test-equal (bit->boolean 5 2) #t)931 (test-equal (bit->boolean 5 0) #t)932 (test-equal (bit->boolean 5 1) #f)933 (test-equal (bit->boolean -2 0) #f)934 (test-equal (bit->boolean -2 1) #t)935 (test-equal (bit->boolean (expt -2 63) 256) #t)936 (test-equal (bit->boolean (expt 2 63) 256) #f)937 (test-equal (arithmetic-shift 15 2) 60)938 (test-equal (arithmetic-shift 15 -2) 3)939 (test-equal (arithmetic-shift -15 2) -60)940 (test-equal (arithmetic-shift -15 -2) -4) ; 2's complement941 (test-equal (arithmetic-shift -31 most-negative-fixnum) -1)942 (test-equal (arithmetic-shift 31 most-negative-fixnum) 0)943 (test-equal (arithmetic-shift b1 0) b1)944 (test-equal (arithmetic-shift (arithmetic-shift b1 -1) 1) b1)945 (test-error (arithmetic-shift 0.1 2))946 ;; XXX Do the following two need to fail? Might as well use the integral value947 (test-error (arithmetic-shift #xf 2.0))948 (test-error (arithmetic-shift #xf -2.0))949 (test-error (arithmetic-shift #xf 2.1))950 (test-error (arithmetic-shift #xf -2.1))951 (test-error (arithmetic-shift +inf.0 2))952 (test-error (arithmetic-shift +nan.0 2))953 (when 64-bits?954 (test-equal (arithmetic-shift (expt 2 31) (- (expt 2 31))) 0))955956 ;; by Jeremy Sydik957 (let ((leftrot32958 (lambda (value amount)959 (let ((shifted (arithmetic-shift value amount)))960 (let ((anded (bitwise-and #xFFFFFFFF shifted)))961 (bitwise-ior anded962 (arithmetic-shift shifted -32)))) )))963 (test-equal "leftrot32 28" (leftrot32 1 28) 268435456)964 (test-equal "leftrot32 29" (leftrot32 1 29) 536870912)965 (test-equal "leftrot32 30" (leftrot32 1 30) 1073741824))966)967968(test-group "string conversion"969970 (test-assert "fix" (number->string 123))971 (test-assert "fix/base" (number->string 123 16))972 (test-assert "flo" (number->string 99.2))973 (test-assert "big" (number->string b1))974 (test-assert "big/base" (number->string b1 2))975 (test-assert "rat" (number->string r1))976 (test-assert "comp" (number->string c1))977978 (test-equal "edge case printing"979 (number->string (expt 2 256) 16)980 "10000000000000000000000000000000000000000000000000000000000000000")981 (test-equal "non-exact multiple of 64 length edge case printing"982 "4000000000000000000000" (number->string (expt 2 65) 8))983 (test-equal "another non-exact multiple of 64 length edge case printing"984 "200000000000000000000000" (number->string (expt 2 70) 8))985 (test-equal "edge case length calculation"986 "10000000000000000000000000000000000000000000000000000000000000000000000" (number->string (expt 2 210) 8))987 (test-equal "positive hexdigit invariance"988 (number->string989 (string->number "123456789abcdef123456789abcdef123456789abcdef" 16)990 16)991 "123456789abcdef123456789abcdef123456789abcdef")992 (test-equal "negative hexdigit invariance"993 (number->string994 (string->number "-123456789abcdef123456789abcdef123456789abcdef" 16)995 16)996 "-123456789abcdef123456789abcdef123456789abcdef")997998 (test-equal "fix" (string->number "123") 123)999 (test-equal "fix/base" (string->number "ff" 16) 255)1000 (test-equal "fix/base-o" (string->number "16" 8) 14)1001 (test-equal "fix/unusual-base" (string->number "1234" 5) 194)1002 (test-equal "fix/wrong-base" (string->number "1234" 4) #f)1003 (test-error "fix/invalid-base" (string->number "1234" 0))1004 (test-error "fix/invalid-base" (string->number "1234" 1))1005 (test-equal "embedded base overrides supplied base" (string->number "#x10" 10) 16)1006 (test-equal "flo" (string->number "123.23") 123.23)1007 (test-equal "flo2" (string->number "1e2") 100.0)1008 (test-assert "big" (show (string->number "123873487384737447")))1009 (test-assert "big/neg" (show (string->number "-123873487384737447")))1010 (test-assert "big/pos" (show (string->number "+123873487384737447")))1011 (test-assert "rat" (show (string->number "123/456")))1012 (test-assert "rat/neg" (show (string->number "-123/456")))1013 (test-assert "rat/pos" (show (string->number "+123/456")))1014 (test-assert "rat2" (show (string->number "#o123/456")))1015 (test-equal "rat/inexact" (show (string->number "#i123/456")) (/ 123.0 456))1016 (test-equal "invalid rat" (string->number "123/0") #f)1017 (test-assert "comp" (show (string->number "+12i")))1018 (test-assert "comp" (show (string->number "12+34i")))1019 (test-assert "comp" (show (string->number "-i")))1020 (test-assert "comp" (show (string->number "99@55")))1021 (test-assert "comp" (show (string->number "1/2@3/4")))1022 (test-assert "comp2" (show (string->number "#x99+55i")))1023 ;; This is to check for a silly problem cause by representing numbers exactly1024 ;; all the way until the end, then converting to inexact. This "silly problem"1025 ;; could probably be exploited in a resource consumption attack.1026 (let* ((t1 (current-seconds))1027 (i1 (string->number "1e1000000"))1028 (i2 (string->number "1.0e1000000"))1029 (e1 (string->number "#e1e1000000"))1030 (e2 (string->number "#e1.0e1000000"))1031 (t2 (current-seconds)))1032 (test-assert "read time for inexacts with large positive exp isn't insanely high" (< (- t2 t1) 2))1033 (test-equal "inexact read back are equal" i2 i1)1034 (test-equal "inexact are inf" +inf.0 i1)1035 (test-equal "exact are equal" e2 e1)1036 (test-equal "exact are false" #f e1))1037 (let* ((t1 (current-seconds))1038 (i1 (string->number "-1e1000000"))1039 (i2 (string->number "-1.0e1000000"))1040 (e1 (string->number "#e-1e1000000"))1041 (e2 (string->number "#e-1.0e1000000"))1042 (t2 (current-seconds)))1043 (test-assert "read time for inexacts with large positive exp isn't insanely high" (< (- t2 t1) 2))1044 (test-equal "negative inexact read back are equal" i2 i1)1045 (test-equal "negative inexact are negative inf" -inf.0 i1)1046 (test-equal "negative exact are equal" e2 e1)1047 (test-equal "negative exact are false" #f e1))1048 (let* ((t1 (current-seconds))1049 (i1 (string->number "1e-1000000"))1050 (i2 (string->number "1.0e-1000000"))1051 (e1 (string->number "#e1e-1000000"))1052 (e2 (string->number "#e1.0e-1000000"))1053 (t2 (current-seconds)))1054 (test-assert "read time for inexacts with large negative exp isn't insanely high" (< (- t2 t1) 2))1055 (test-equal "inexact read back are equal" i2 i1)1056 (test-equal "inexact are 0" +0.0 i1)1057 (test-equal "exact are equal" e2 e1)1058 (test-equal "exact are false" #f e1))10591060 (test-group "read/write invariance of simple integers for different radices"1061 (let lp ((radix 2)1062 (digit 0))1063 (cond ((= digit radix) (lp (add1 radix) 0))1064 ((<= radix 36)1065 (let* ((char (string-ref (number->string digit radix) 0))1066 (str (make-string 10 char)))1067 (test-equal (sprintf "radix ~A digits ~S" radix digit)1068 (number->string (string->number str) radix)1069 (if (char=? char #\0) "0" str)))))))1070)10711072(test-group "non-standard type procedures"10731074 (test-equal "fixnum" (fixnum? max-fix) #t)10751076 (test-equal "bignum" (bignum? b1) #t)1077 (test-equal "bignum" (bignum? min-big) #t)10781079 (test-equal "ratnum" (ratnum? r1) #t)10801081 (test-equal "nan: fix" (nan? 1) #f)1082 (test-equal "nan: flo" (nan? 1.0) #f)1083 (test-equal "nan: +inf" (nan? (/ 1.0 0.0)) #f)1084 (test-equal "nan: -inf" (nan? (/ -1.0 0.0)) #f)1085 (test-equal "nan: nan" (nan? (/ 0.0 0.0)) #t)1086 (test-equal "nan: nan+nani" (nan? (make-rectangular (/ 0.0 0.0) (/ 0.0 0.0))) #t)1087 (test-equal "nan: flo+nani" (nan? (make-rectangular 1.0 (/ 0.0 0.0))) #t)1088 (test-equal "nan: nan+floi" (nan? (make-rectangular (/ 0.0 0.0) 1.0)) #t)1089 (test-error "nan: no number" (nan? 'x))10901091 (test-equal "finite: fix" (finite? 1) #t)1092 (test-equal "finite: flo" (finite? 1.0) #t)1093 (test-equal "finite: +inf" (finite? (/ 1.0 0.0)) #f)1094 (test-equal "finite: -inf" (finite? (/ 1.0 0.0)) #f)1095 (test-equal "finite: nan" (finite? (/ 0.0 0.0)) #f)1096 (test-equal "finite: nan+floi" (finite? (make-rectangular (/ 0.0 0.0) 1.0)) #f)1097 (test-equal "finite: inf+infi" (finite? (make-rectangular (/ 1.0 0.0) (/ 1.0 0.0))) #f)1098 (test-equal "finite: flo+infi" (finite? (make-rectangular 1.0 (/ 1.0 0.0))) #f)1099 (test-equal "finite: inf+floi" (finite? (make-rectangular (/ 1.0 0.0) 1.0)) #f)1100 (test-error "finite: no number" (finite? 'x))11011102 (test-equal "infinite: fix" (infinite? 1) #f)1103 (test-equal "infinite: flo" (infinite? 1.0) #f)1104 (test-equal "infinite: +inf" (infinite? (/ 1.0 0.0)) #t)1105 (test-equal "infinite: -inf" (infinite? (/ 1.0 0.0)) #t)1106 (test-equal "infinite: nan" (infinite? (/ 0.0 0.0)) #f)1107 (test-equal "infinite: inf+infi" (infinite? (make-rectangular (/ 1.0 0.0) (/ 1.0 0.0))) #t)1108 (test-equal "infinite: flo+infi" (infinite? (make-rectangular 1.0 (/ 1.0 0.0))) #t)1109 (test-equal "infinite: inf+floi" (infinite? (make-rectangular (/ 1.0 0.0) 1.0)) #t)1110 (test-error "infinite: no number" (infinite? 'x))11111112 (test-equal "cplxnum: compintintnum" (cplxnum? c1) #t)1113 (test-equal "cplxnum: compintflointnum" (cplxnum? 1.0+1i) #t)1114 (test-equal "cplxnum: compflointnum" (cplxnum? c2) #t)1115 (test-equal "cplxnum: compfloflonum" (cplxnum? 3.4-4.3i) #t)1116 (test-equal "not cplxnum: fixnum" (cplxnum? 1) #f)1117)11181119;; The usual comparator doesn't work, because zero or a very small number1120;; is many times any other small number, but the absolute difference should1121;; be minimal, so we compare for that instead.1122(parameterize ((current-test-epsilon 1e-9)1123 (current-test-comparator1124 (lambda (exp act)1125 (or (and (nan? exp) (nan? act))1126 (and (< (abs (- (real-part exp) (real-part act)))1127 (current-test-epsilon))1128 (< (abs (- (imag-part exp) (imag-part act)))1129 (current-test-epsilon)))))))11301131 ;; We're using (acos (cos x)) instead of just (acos y) because we want1132 ;; to test the compiler's specialization rules of cos output.11331134 (test-group "trigonometric functions"1135 (test-group "flonums"1136 ;; Note: we don't *actually* distinguish -nan from +nan, but whatever :)1137 (test-equal "acos(-inf)" (acos -inf.0) -nan.0)1138 (test-equal "acos(<small number>)" (acos -1e100) -nan.0)1139 (test-equal "cos(-1/3pi)" (cos (- (/ pi 3))) 0.5)1140 (test-equal "acos(cos(-1/3pi))" (acos (cos (- (/ pi 3)))) (/ pi 3))1141 (test-equal "cos(-1/4pi)" (cos (- (/ pi 4))) 0.7071067811865476)1142 (test-equal "acos(cos(-1/4pi))" (acos (cos (- (/ pi 4)))) (/ pi 4))1143 (test-equal "cos(-1/2pi)" (cos (- (/ pi 2))) 0.0)1144 (test-equal "acos(cos(-1/2pi))" (acos (cos (- (/ pi 2)))) (/ pi 2))1145 (test-equal "cos(-pi)" (cos (- pi)) -1.0)1146 (test-equal "acos(cos(-pi))" (acos (cos (- pi))) pi)1147 (test-equal "cos(0)" (cos 0.0) 1.0)1148 (test-equal "acos(cos(0))" (acos (cos 0.0)) 0.0)1149 (test-equal "cos( 1/4pi)" (cos (/ pi 4)) 0.7071067811865476)1150 (test-equal "acos(cos( 1/4pi))" (acos (cos (/ pi 4))) (/ pi 4))1151 (test-equal "cos( 1/3pi)" (cos (/ pi 3)) 0.5)1152 (test-equal "acos(cos( 1/3pi))" (acos (cos (/ pi 3))) (/ pi 3))1153 (test-equal "cos( 1/2pi)" (cos (/ pi 2)) 0.0)1154 (test-equal "acos(cos( 1/2pi))" (acos (cos (/ pi 2))) (/ pi 2))1155 (test-equal "cos( 2/3pi)" (cos (/ (* 2 pi) 3)) -0.5)1156 (test-equal "acos(cos( 2/3pi))" (acos (cos (/ (* 2 pi) 3))) (/ (* 2 pi) 3))1157 (test-equal "cos( 3/4pi)" (cos (* (/ pi 4) 3)) -0.7071067811865476)1158 (test-equal "acos(cos( 3/4pi))" (acos (cos (* (/ pi 4) 3))) (* (/ pi 4) 3))1159 (test-equal "cos( pi)" (cos pi) -1.0)1160 (test-equal "acos(cos( pi))" (acos (cos pi)) pi)1161 (test-equal "cos( 3/2pi)" (cos (+ pi (/ pi 2))) 0.0)1162 (test-equal "acos(cos( 3/2pi))" (acos (cos (+ pi (/ pi 2)))) (/ pi 2))1163 (test-equal "cos( 4/3pi)" (cos (+ pi (/ pi 3))) -0.5)1164 (test-equal "acos(cos( 4/3pi))" (acos (cos (+ pi (/ pi 3)))) (* 2 (/ pi 3)))1165 (test-equal "cos( 5/4pi)" (cos (+ pi (/ pi 4))) -0.7071067811865476)1166 (test-equal "acos(cos( 5/4pi))" (acos (cos (+ pi (/ pi 4)))) (* 3 (/ pi 4)))1167 (test-equal "cos( 2pi)" (cos (* 2 pi)) 1.0)1168 (test-equal "acos(cos( 2pi))" (acos (cos (* 2 pi))) 0)1169 (test-equal "acos(pi)" (acos pi) 0.0+1.81152627246085i)1170 (test-equal "acos(+inf)" (acos +inf.0) -nan.0)11711172 (test-equal "asin(-inf)" (asin -inf.0) -nan.0)1173 (test-equal "asin(<small number>)" (asin -1e100) -nan.0)1174 (test-equal "sin(-1/3pi)" (sin (- (/ pi 3))) -0.8660254037844386)1175 (test-equal "asin(sin(-1/3pi))" (asin (sin (- (/ pi 3)))) (- (/ pi 3)))1176 (test-equal "sin(-1/4pi)" (sin (- (/ pi 4))) -0.7071067811865476)1177 (test-equal "asin(sin(-1/4pi))" (asin (sin (- (/ pi 4)))) (- (/ pi 4)))1178 (test-equal "sin(-1/2pi)" (sin (- (/ pi 2))) -1.0)1179 (test-equal "asin(sin(-1/2pi))" (asin (sin (- (/ pi 2)))) (- (/ pi 2)))1180 (test-equal "sin(-pi)" (sin (- pi)) 0.0)1181 (test-equal "asin(sin(-pi))" (asin (sin (- pi))) 0.0)1182 (test-equal "sin(0)" (sin 0.0) 0.0)1183 (test-equal "asin(sin(0))" (asin (sin 0.0)) 0.0)1184 (test-equal "sin( 1/4pi)" (sin (/ pi 4)) 0.7071067811865476)1185 (test-equal "asin(sin( 1/4pi))" (asin (sin (/ pi 4))) (/ pi 4))1186 (test-equal "sin( 1/3pi)" (sin (/ pi 3)) 0.8660254037844386)1187 (test-equal "asin(sin( 1/3pi))" (asin (sin (/ pi 3))) (/ pi 3))1188 (test-equal "sin( 1/2pi)" (sin (/ pi 2)) 1.0)1189 (test-equal "asin(sin( 1/2pi))" (asin (sin (/ pi 2))) (/ pi 2))1190 (test-equal "sin( 2/3pi)" (sin (/ (* 2 pi) 3)) 0.8660254037844386)1191 (test-equal "asin(sin( 2/3pi))" (asin (sin (/ (* 2 pi) 3))) (/ pi 3))1192 (test-equal "sin( 3/4pi)" (sin (* (/ pi 4) 3)) 0.7071067811865476)1193 (test-equal "asin(sin( 3/4pi))" (asin (sin (* (/ pi 4) 3))) (/ pi 4))1194 (test-equal "sin( pi)" (sin pi) 0.0)1195 (test-equal "asin(sin( pi))" (asin (sin pi)) 0.0)1196 (test-equal "sin( 3/2pi)" (sin (+ pi (/ pi 2))) -1.0)1197 (test-equal "asin(sin( 3/2pi))" (asin (sin (+ pi (/ pi 2)))) (- (/ pi 2)))1198 (test-equal "sin( 4/3pi)" (sin (+ pi (/ pi 3))) -0.8660254037844386)1199 (test-equal "asin(sin( 4/3pi))" (asin (sin (+ pi (/ pi 3)))) (- (/ pi 3)))1200 (test-equal "sin( 5/4pi)" (sin (+ pi (/ pi 4))) -0.7071067811865476)1201 (test-equal "asin(sin( 5/4pi))" (asin (sin (+ pi (/ pi 4)))) (- (/ pi 4)))1202 (test-equal "sin( 2pi)" (sin (* 2 pi)) 0.0)1203 (test-equal "asin(sin( 2pi))" (asin (sin (* 2 pi))) 0.0)1204 (test-equal "asin(pi)" (asin pi) 1.57079632679490-1.81152627246085i)1205 (test-equal "asin(+inf)" (asin +inf.0) -nan.0)12061207 (test-equal "atan(-inf)" (atan -inf.0) (- (/ pi 2)))1208 (test-equal "atan(<small number>)" (atan -1e100) (- (/ pi 2)))1209 (test-equal "tan(-1/3pi)" (tan (- (/ pi 3))) -1.7320508075688773)1210 (test-equal "atan(tan(-1/3pi))" (atan (tan (- (/ pi 3)))) (- (/ pi 3)))1211 (test-equal "tan(-1/4pi)" (tan (- (/ pi 4))) -1.0)1212 (test-equal "atan(tan(-1/4pi))" (atan (tan (- (/ pi 4)))) (- (/ pi 4)))1213 ;; NOTE: tan(-(/ pi 2)) should be -inf(?), but isn't. Is that a bug?1214 (test-equal "tan(-pi)" (tan (- pi)) 0.0)1215 (test-equal "atan(tan(-pi))" (atan (tan (- pi))) 0.0)1216 (test-equal "tan(0)" (tan 0.0) 0.0)1217 (test-equal "atan(tan(0))" (atan (tan 0.0)) 0.0)1218 (test-equal "tan( 1/4pi)" (tan (/ pi 4)) 1.0)1219 (test-equal "atan(tan( 1/4pi))" (atan (tan (/ pi 4))) (/ pi 4))1220 (test-equal "tan( 1/3pi)" (tan (/ pi 3)) 1.7320508075688773)1221 (test-equal "atan(tan( 1/3pi))" (atan (tan (/ pi 3))) (/ pi 3))1222 (test-equal "tan( 2/3pi)" (tan (/ (* 2 pi) 3)) -1.7320508075688773)1223 (test-equal "atan(tan( 2/3pi))" (atan (tan (/ (* 2 pi) 3))) (- (/ pi 3)))1224 (test-equal "tan( 3/4pi)" (tan (* (/ pi 4) 3)) -1.0)1225 (test-equal "atan(tan( 3/4pi))" (atan (tan (* (/ pi 4) 3))) (- (/ pi 4)))1226 (test-equal "tan( pi)" (tan pi) 0.0)1227 (test-equal "atan(tan( pi))" (atan (tan pi)) 0.0)1228 (test-equal "tan( 4/3pi)" (tan (+ pi (/ pi 3))) 1.7320508075688773)1229 (test-equal "atan(tan( 4/3pi))" (atan (tan (+ pi (/ pi 3)))) (/ pi 3))1230 (test-equal "tan( 5/4pi)" (tan (+ pi (/ pi 4))) 1.0)1231 (test-equal "atan(tan( 5/4pi))" (atan (tan (+ pi (/ pi 4)))) (/ pi 4))1232 (test-equal "tan( 2pi)" (tan (* 2 pi)) 0.0)1233 (test-equal "atan(tan( 2pi))" (atan (tan (* 2 pi))) 0.0)1234 (test-equal "atan(pi)" (atan 1e100) (/ pi 2))1235 (test-equal "atan(+inf)" (atan +inf.0) (/ pi 2))12361237 (test-equal "atan2(3, tan(pi))" (atan 3 (tan pi)) (/ pi 2))1238 (test-equal "atan2(3, -tan(pi))" (atan 3 (- (tan pi))) (/ pi 2))1239 (test-equal "atan2(-3, tan(pi))" (atan -3 (tan pi)) (- (/ pi 2)))1240 (test-equal "atan2(-3, -tan(pi))" (atan -3 (- (tan pi))) (- (/ pi 2)))1241 ;; Equivalence described in R5RS1242 (test-equal "atan2(1, 2) = angle(2+i)"1243 (angle (make-rectangular 2 1)) (atan 1 2))1244 (test-equal "atan2(1, b1) = angle(2+i)"1245 (angle (make-rectangular b1 1)) (atan 1 b1))1246 (test-equal "atan2(b1, 1) = angle(2+i)"1247 (angle (make-rectangular 1 b1)) (atan b1 1))1248 (test-equal "atan2(-0.1, 3.2) = angle(3.2-0.1i)"1249 (angle (make-rectangular 3.2 -0.1)) (atan -0.1 3.2))1250 )12511252 ;; Cross-checked against Gauche and Scheme48's output1253 (test-group "compnums"1254 (test-equal "cos(0.0+1.0i)" (cos (make-rectangular 0.0 1.0))1255 1.5430806348152437)1256 (test-equal "acos(cos(0.0+1.0i))" (acos (cos (make-rectangular 0.0 1.0)))1257 0.0+1.0i)1258 (test-equal "cos(0.0-1.0i)" (cos (make-rectangular 0.0 -1.0))1259 1.5430806348152437)1260 (test-equal "acos(cos(0.0-1.0i))" (acos (cos (make-rectangular 0.0 -1.0)))1261 0.0+1.0i)1262 (test-equal "cos(0.0+3.0i)" (cos (make-rectangular 0.0 3.0))1263 10.067661995777765)1264 (test-equal "acos(cos(0.0+3.0i))" (acos (cos (make-rectangular 0.0 3.0)))1265 0.0+3.0i)1266 (test-equal "cos(0.0-3.0i)" (cos (make-rectangular 0.0 -3.0))1267 10.067661995777765)1268 (test-equal "acos(cos(0.0-3.0i))" (acos (cos (make-rectangular 0.0 -3.0)))1269 0.0+3.0i)1270 (test-equal "cos(0.5+0.5i)"1271 (cos (make-rectangular 0.5 0.5))1272 (make-rectangular 0.9895848833999199 -0.24982639750046154))1273 (test-equal "acos(cos(0.5+0.5i))"1274 (acos (cos (make-rectangular 0.5 0.5)))1275 (make-rectangular 0.5 0.5))1276 (test-equal "cos(0.5-0.5i)"1277 (cos (make-rectangular 0.5 -0.5))1278 (make-rectangular 0.9895848833999199 0.24982639750046154))1279 (test-equal "acos(cos(0.5-0.5i))"1280 (acos (cos (make-rectangular 0.5 -0.5)))1281 (make-rectangular 0.5 -0.5))1282 (test-equal "cos(-0.5-0.5i)"1283 (cos (make-rectangular -0.5 -0.5))1284 (make-rectangular 0.9895848833999199 -0.24982639750046154))1285 (test-equal "acos(cos(-0.5-0.5i))"1286 (acos (cos (make-rectangular -0.5 -0.5)))1287 (make-rectangular 0.5 0.5))1288 (test-equal "cos(-0.5+0.5i)"1289 (cos (make-rectangular -0.5 0.5))1290 (make-rectangular 0.9895848833999199 0.24982639750046154))1291 (test-equal "acos(cos(-0.5+0.5i))"1292 (acos (cos (make-rectangular -0.5 0.5)))1293 (make-rectangular 0.5 -0.5))1294 (test-equal "cos(-1.0+1.0i)"1295 (cos (make-rectangular -1.0 1.0))1296 (make-rectangular 0.8337300251311491 0.9888977057628651))1297 (test-equal "acos(cos(-1.0+1.0i))"1298 (acos (cos (make-rectangular -1.0 1.0)))1299 (make-rectangular 1.0 -1.0))1300 (test-equal "cos(-1.0-1.0i)"1301 (cos (make-rectangular -1.0 -1.0))1302 (make-rectangular 0.8337300251311491 -0.9888977057628651))1303 (test-equal "acos(cos(-1.0-1.0i))"1304 (acos (cos (make-rectangular -1.0 -1.0)))1305 (make-rectangular 1.0 1.0))1306 (test-equal "cos(1.0-1.0i)"1307 (cos (make-rectangular 1.0 -1.0))1308 (make-rectangular 0.8337300251311491 0.9888977057628651))1309 (test-equal "acos(cos(1.0-1.0i))"1310 (acos (cos (make-rectangular 1.0 -1.0)))1311 (make-rectangular 1.0 -1.0))1312 (test-equal "cos(1.0+1.0i)"1313 (cos (make-rectangular 1.0 1.0))1314 (make-rectangular 0.8337300251311491 -0.9888977057628651))1315 (test-equal "acos(cos(1.0+1.0i))"1316 (acos (cos (make-rectangular 1.0 1.0)))1317 (make-rectangular 1.0 1.0))1318 (test-equal "cos(2.0+3.0i)"1319 (cos (make-rectangular 2.0 3.0))1320 (make-rectangular -4.189625690968807 -9.109227893755337))1321 (test-equal "acos(cos(2.0+3.0i))"1322 (acos (cos (make-rectangular 2.0 3.0)))1323 (make-rectangular 2.0 3.0))1324 (test-equal "cos(-2.0+3.0i)"1325 (cos (make-rectangular -2.0 3.0))1326 (make-rectangular -4.189625690968807 9.109227893755337))1327 (test-equal "acos(cos(-2.0+3.0i))"1328 (acos (cos (make-rectangular -2.0 3.0)))1329 (make-rectangular 2.0 -3.0))1330 (test-equal "cos(-2.0-3.0i)"1331 (cos (make-rectangular -2.0 -3.0))1332 (make-rectangular -4.189625690968807 -9.109227893755337))1333 (test-equal "acos(cos(-2.0-3.0i))"1334 (acos (cos (make-rectangular -2.0 -3.0)))1335 (make-rectangular 2.0 3.0))1336 (test-equal "cos(2.0-3.0i)"1337 (cos (make-rectangular 2.0 -3.0))1338 (make-rectangular -4.189625690968807 9.109227893755337))1339 (test-equal "acos(cos(2.0-3.0i))"1340 (acos (cos (make-rectangular 2.0 -3.0)))1341 (make-rectangular 2.0 -3.0))1342 ;; Specialization check1343 (test-equal "cos(acos(2.0-3.0i))"1344 (cos (acos (make-rectangular 2.0 -3.0)))1345 (make-rectangular 2.0 -3.0))13461347 (test-equal "sin(0.0+1.0i)"1348 (sin (make-rectangular 0.0 1.0))1349 (make-rectangular 0.0 1.1752011936438014))1350 (test-equal "asin(sin(0.0+1.0i))"1351 (asin (sin (make-rectangular 0.0 1.0)))1352 (make-rectangular 0.0 1.0))1353 (test-equal "sin(0.0-1.0i)"1354 (sin (make-rectangular 0.0 -1.0))1355 (make-rectangular 0.0 -1.1752011936438014))1356 (test-equal "asin(sin(0.0-1.0i))"1357 (asin (sin (make-rectangular 0.0 -1.0)))1358 (make-rectangular 0.0 -1.0))1359 (test-equal "sin(0.0+3.0i)"1360 (sin (make-rectangular 0.0 3.0))1361 (make-rectangular 0.0 10.017874927409903))1362 (test-equal "asin(sin(0.0+3.0i))"1363 (asin (sin (make-rectangular 0.0 3.0)))1364 (make-rectangular 0.0 3.0))1365 (test-equal "sin(0.0-3.0i)"1366 (sin (make-rectangular 0.0 -3.0))1367 (make-rectangular 0.0 -10.017874927409903))1368 (test-equal "asin(sin(0.0-3.0i))"1369 (asin (sin (make-rectangular 0.0 -3.0)))1370 (make-rectangular 0.0 -3.0))1371 (test-equal "sin(0.5+0.5i)"1372 (sin (make-rectangular 0.5 0.5))1373 (make-rectangular 0.5406126857131534 0.4573041531842493))1374 (test-equal "asin(sin(0.5+0.5i))"1375 (asin (sin (make-rectangular 0.5 0.5)))1376 (make-rectangular 0.5 0.5))1377 (test-equal "sin(0.5-0.5i)"1378 (sin (make-rectangular 0.5 -0.5))1379 (make-rectangular 0.5406126857131534 -0.4573041531842493))1380 (test-equal "asin(sin(0.5-0.5i))"1381 (asin (sin (make-rectangular 0.5 -0.5)))1382 (make-rectangular 0.5 -0.5))1383 (test-equal "sin(-0.5-0.5i)"1384 (sin (make-rectangular -0.5 -0.5))1385 (make-rectangular -0.5406126857131534 -0.4573041531842493))1386 (test-equal "asin(sin(-0.5-0.5i))"1387 (asin (sin (make-rectangular -0.5 -0.5)))1388 (make-rectangular -0.5 -0.5))1389 (test-equal "sin(-0.5+0.5i)"1390 (sin (make-rectangular -0.5 0.5))1391 (make-rectangular -0.5406126857131534 +0.457304153184249))1392 (test-equal "asin(sin(-0.5+0.5i))"1393 (asin (sin (make-rectangular -0.5 0.5)))1394 (make-rectangular -0.5 +0.5))1395 (test-equal "sin(-1.0+1.0i)"1396 (sin (make-rectangular -1.0 1.0))1397 (make-rectangular -1.2984575814159773 0.6349639147847361))1398 (test-equal "asin(sin(-1.0+1.0i))"1399 (asin (sin (make-rectangular -1.0 1.0)))1400 (make-rectangular -1.0 1.0))1401 (test-equal "sin(-1.0-1.0i)"1402 (sin (make-rectangular -1.0 -1.0))1403 (make-rectangular -1.2984575814159773 -0.6349639147847361))1404 (test-equal "asin(sin(-1.0-1.0i))"1405 (asin (sin (make-rectangular -1.0 -1.0)))1406 (make-rectangular -1.0 -1.0))1407 (test-equal "sin(1.0-1.0i)"1408 (sin (make-rectangular 1.0 -1.0))1409 (make-rectangular 1.2984575814159773 -0.6349639147847361))1410 (test-equal "asin(sin(1.0-1.0i))"1411 (asin (sin (make-rectangular 1.0 -1.0)))1412 (make-rectangular 1.0 -1.0))1413 (test-equal "sin(2.0+3.0i)"1414 (sin (make-rectangular 2.0 3.0))1415 (make-rectangular 9.15449914691143 -4.168906959966565))1416 (test-equal "asin(sin(2.0+3.0i))"1417 (asin (sin (make-rectangular 2.0 3.0)))1418 (make-rectangular 1.1415926535898042 -3.0))1419 (test-equal "sin(-2.0+3.0i)"1420 (sin (make-rectangular -2.0 3.0))1421 (make-rectangular -9.15449914691143 -4.168906959966565))1422 (test-equal "asin(sin(-2.0+3.0i))"1423 (asin (sin (make-rectangular -2.0 3.0)))1424 (make-rectangular -1.1415926535898042 -3.0))1425 (test-equal "sin(-2.0-3.0i)"1426 (sin (make-rectangular -2.0 -3.0))1427 (make-rectangular -9.15449914691143 4.168906959966565))1428 (test-equal "asin(sin(-2.0-3.0i))"1429 (asin (sin (make-rectangular -2.0 -3.0)))1430 (make-rectangular -1.1415926535898042 3.0))1431 (test-equal "sin(2.0-3.0i)"1432 (sin (make-rectangular 2.0 -3.0))1433 (make-rectangular 9.15449914691143 4.168906959966565))1434 (test-equal "asin(sin(2.0-3.0i))"1435 (asin (sin (make-rectangular 2.0 -3.0)))1436 (make-rectangular 1.1415926535898042 3.0))1437 ;; Specialization check1438 (test-equal "sin(asin(1.1415926535898042+3.0i))"1439 (sin (asin (make-rectangular 2.0 3.0)))1440 (make-rectangular 2.0 3.0))14411442 (test-equal "tan(0.0+1.0i)"1443 (tan (make-rectangular 0.0 1.0))1444 (make-rectangular 0.0 0.7615941559557649))1445 (test-equal "atan(tan(0.0+1.0i))"1446 (atan (tan (make-rectangular 0.0 1.0)))1447 (make-rectangular 0.0 1.0))1448 (test-equal "tan(0.0-1.0i)"1449 (tan (make-rectangular 0.0 -1.0))1450 (make-rectangular 0.0 -0.7615941559557649))1451 (test-equal "atan(tan(0.0-1.0i))"1452 (atan (tan (make-rectangular 0.0 -1.0)))1453 (make-rectangular 0.0 -1.0))1454 (test-equal "tan(0.0+3.0i)"1455 (tan (make-rectangular 0.0 3.0))1456 (make-rectangular 0.0 0.9950547536867306))1457 (test-equal "atan(tan(0.0+3.0i))"1458 (atan (tan (make-rectangular 0.0 3.0)))1459 (make-rectangular 0.0 3.0))1460 (test-equal "tan(0.0-3.0i)"1461 (tan (make-rectangular 0.0 -3.0))1462 (make-rectangular 0.0 -0.9950547536867306))1463 (test-equal "atan(tan(0.0-3.0i))"1464 (atan (tan (make-rectangular 0.0 -3.0)))1465 (make-rectangular 0.0 -3.0))1466 (test-equal "tan(0.5+0.5i)"1467 (tan (make-rectangular 0.5 0.5))1468 (make-rectangular 0.4038964553160257 0.5640831412674985))1469 (test-equal "atan(tan(0.5+0.5i))"1470 (atan (tan (make-rectangular 0.5 0.5)))1471 (make-rectangular 0.5 0.5))1472 (test-equal "tan(0.5-0.5i)"1473 (tan (make-rectangular 0.5 -0.5))1474 (make-rectangular 0.4038964553160257 -0.5640831412674985))1475 (test-equal "atan(tan(0.5-0.5i))"1476 (atan (tan (make-rectangular 0.5 -0.5)))1477 (make-rectangular 0.5 -0.5))1478 (test-equal "tan(-0.5-0.5i)"1479 (tan (make-rectangular -0.5 -0.5))1480 (make-rectangular -0.4038964553160257 -0.5640831412674985))1481 (test-equal "atan(tan(-0.5-0.5i))"1482 (atan (tan (make-rectangular -0.5 -0.5)))1483 (make-rectangular -0.5 -0.5))1484 (test-equal "tan(-0.5+0.5i)"1485 (tan (make-rectangular -0.5 0.5))1486 (make-rectangular -0.4038964553160257 0.5640831412674985))1487 (test-equal "atan(tan(-0.5+0.5i))"1488 (atan (tan (make-rectangular -0.5 0.5)))1489 (make-rectangular -0.5 0.5))1490 (test-equal "tan(-1.0+1.0i)"1491 (tan (make-rectangular -1.0 1.0))1492 (make-rectangular -0.27175258531951174 1.0839233273386948))1493 (test-equal "atan(tan(-1.0+1.0i))"1494 (atan (tan (make-rectangular -1.0 1.0)))1495 (make-rectangular -1.0 1.0))1496 (test-equal "tan(-1.0-1.0i)"1497 (tan (make-rectangular -1.0 -1.0))1498 (make-rectangular -0.27175258531951174 -1.0839233273386948))1499 (test-equal "atan(tan(-1.0-1.0i))"1500 (atan (tan (make-rectangular -1.0 -1.0)))1501 (make-rectangular -1.0 -1.0))1502 (test-equal "tan(1.0-1.0i)"1503 (tan (make-rectangular 1.0 -1.0))1504 (make-rectangular 0.27175258531951174 -1.0839233273386948))1505 (test-equal "atan(tan(1.0-1.0i))"1506 (atan (tan (make-rectangular 1.0 -1.0)))1507 (make-rectangular 1.0 -1.0))1508 (test-equal "tan(2.0+3.0i)"1509 (tan (make-rectangular 2.0 3.0))1510 (make-rectangular -0.0037640256415040815 1.0032386273536098))1511 (test-equal "atan(tan(2.0+3.0i))"1512 (atan (tan (make-rectangular 2.0 3.0)))1513 (make-rectangular -1.1415926535898042 3.0))1514 (test-equal "tan(-2.0+3.0i)"1515 (tan (make-rectangular -2.0 3.0))1516 (make-rectangular 0.0037640256415040815 1.0032386273536098))1517 (test-equal "atan(tan(-2.0+3.0i))"1518 (atan (tan (make-rectangular -2.0 3.0)))1519 (make-rectangular 1.1415926535898042 3.0))1520 (test-equal "tan(-2.0-3.0i)"1521 (tan (make-rectangular -2.0 -3.0))1522 (make-rectangular 0.0037640256415040815 -1.0032386273536098))1523 (test-equal "atan(tan(-2.0-3.0i))"1524 (atan (tan (make-rectangular -2.0 -3.0)))1525 (make-rectangular 1.1415926535898042 -3.0))1526 (test-equal "tan(2.0-3.0i)"1527 (tan (make-rectangular 2.0 -3.0))1528 (make-rectangular -0.0037640256415040815 -1.0032386273536098))1529 (test-equal "atan(tan(2.0-3.0i))"1530 (atan (tan (make-rectangular 2.0 -3.0)))1531 (make-rectangular -1.1415926535898042 -3.0))1532 ;; Specialization check1533 (test-equal "tan(atan(2.0-3.0i))"1534 (tan (atan (make-rectangular 2.0 -3.0)))1535 (make-rectangular 2.0 -3.0))15361537 )15381539 ;; This is just a handful to determine that we're able to accept these.1540 ;; Maybe determine better values to test with?1541 (test-group "bignums"1542 (test-equal "acos(<negative bignum>)" (acos (- b1)) -nan.0)1543 ;; These are bogus (maybe the negative ones too!), but I don't want to1544 ;; "fix" them by copying the output and assume it's alright.1545 #;(test-equal "acos(<bignum>)" (acos b1) +nan.0)1546 (test-equal "asin(<negative bignum>)" (asin (- b1)) -nan.0)1547 #;(test-equal "asin(<bignum>)" (asin b1) +nan.0)1548 (test-equal "atan(<negative bignum>)" (atan (- b1)) (- (/ pi 2)))1549 (test-equal "atan(<bignum>)" (atan b1) (/ pi 2)))15501551 ;; This should probably be enough; we're only testing conversion to flonums1552 ;; and specialization. The actual functionality of cos is checked above.1553 (test-group "fixnums"1554 (test-equal "cos(0)" (cos 0) 1.0)1555 (test-equal "acos(0)" (acos 0) (/ pi 2))1556 (test-equal "cos(1)" (cos 1) (cos 1.0))1557 (test-equal "acos(1)" (acos 1) 0.0)1558 (test-equal "cos(-1)" (cos -1) (cos -1.0))1559 (test-equal "acos(-1)" (acos -1) pi)1560 (test-equal "acos(-2)" (acos -2) (make-rectangular pi -1.31695789692482))1561 (test-equal "acos(2)" (acos 2) 0.0+1.31695789692482i)1562 (test-equal "asin(1)" (asin 1) (/ pi 2))1563 (test-equal "asin(-1)" (asin -1) (/ pi -2))1564 (test-equal "asin(2)" (asin 2) (make-rectangular (/ pi 2) -1.31695789692482))1565 (test-equal "asin(-2)" (asin -2) (make-rectangular (/ pi -2) 1.31695789692482)))15661567 (test-group "ratnums"1568 (test-equal "acos(<small number>)" (acos (/ -999999999 2)) -nan.0)1569 (test-equal "cos(-1/3pi)" (cos (- (/ ratpi 3))) 0.5)1570 (test-equal "acos(cos(-1/3pi))" (acos (cos (- (/ ratpi 3)))) (/ pi 3))1571 (test-equal "cos(-1/4pi)" (cos (- (/ ratpi 4))) 0.7071067811865476)1572 (test-equal "acos(cos(-1/4pi))" (acos (cos (- (/ ratpi 4)))) (/ pi 4))1573 (test-equal "cos(-1/2pi)" (cos (- (/ ratpi 2))) 0.0)1574 (test-equal "acos(cos(-1/2pi))" (acos (cos (- (/ ratpi 2)))) (/ pi 2))1575 (test-equal "cos(-pi)" (cos (- ratpi)) -1.0)1576 (test-equal "acos(cos(-pi))" (acos (cos (- ratpi))) pi)1577 (test-equal "cos(0)" (cos 0.0) 1.0)1578 (test-equal "acos(cos(0))" (acos (cos 0.0)) 0.0)1579 (test-equal "cos( 1/4pi)" (cos (/ ratpi 4)) 0.7071067811865476)1580 (test-equal "acos(cos( 1/4pi))" (acos (cos (/ ratpi 4))) (/ pi 4))1581 (test-equal "cos( 1/3pi)" (cos (/ ratpi 3)) 0.5)1582 (test-equal "acos(cos( 1/3pi))" (acos (cos (/ ratpi 3))) (/ pi 3))1583 (test-equal "cos( 1/2pi)" (cos (/ ratpi 2)) 0.0)1584 (test-equal "acos(cos( 1/2pi))" (acos (cos (/ ratpi 2))) (/ pi 2))1585 (test-equal "cos( 2/3pi)" (cos (/ (* 2 ratpi) 3)) -0.5)1586 (test-equal "acos(cos( 2/3pi))" (acos (cos (/ (* 2 ratpi) 3))) (/ (* 2 pi) 3))1587 (test-equal "cos( 3/4pi)" (cos (* (/ ratpi 4) 3)) -0.7071067811865476)1588 (test-equal "acos(cos( 3/4pi))" (acos (cos (* (/ ratpi 4) 3))) (* (/ pi 4) 3))1589 (test-equal "cos( pi)" (cos ratpi) -1.0)1590 (test-equal "acos(cos( pi))" (acos (cos ratpi)) pi)1591 (test-equal "cos( 3/2pi)" (cos (+ ratpi (/ ratpi 2))) 0.0)1592 (test-equal "acos(cos( 3/2pi))" (acos (cos (+ ratpi (/ ratpi 2)))) (/ pi 2))1593 (test-equal "cos( 4/3pi)" (cos (+ ratpi (/ ratpi 3))) -0.5)1594 (test-equal "acos(cos( 4/3pi))" (acos (cos (+ ratpi (/ ratpi 3)))) (* 2 (/ pi 3)))1595 (test-equal "cos( 5/4pi)" (cos (+ ratpi (/ ratpi 4))) -0.7071067811865476)1596 (test-equal "acos(cos( 5/4pi))" (acos (cos (+ ratpi (/ ratpi 4)))) (* 3 (/ pi 4)))1597 (test-equal "cos( 2pi)" (cos (* 2 pi)) 1.0)1598 (test-equal "acos(cos( 2pi))" (acos (cos (* 2 ratpi))) 0)15991600 (test-equal "sin(-1/3pi)" (sin (- (/ ratpi 3))) -0.8660254037844386)1601 (test-equal "asin(sin(-1/3pi))" (asin (sin (- (/ ratpi 3)))) (- (/ pi 3)))1602 (test-equal "sin(-1/4pi)" (sin (- (/ ratpi 4))) -0.7071067811865476)1603 (test-equal "asin(sin(-1/4pi))" (asin (sin (- (/ ratpi 4)))) (- (/ pi 4)))1604 (test-equal "sin(-1/2pi)" (sin (- (/ ratpi 2))) -1.0)1605 (test-equal "asin(sin(-1/2pi))" (asin (sin (- (/ ratpi 2)))) (- (/ pi 2)))1606 (test-equal "sin(-pi)" (sin (- ratpi)) 0.0)1607 (test-equal "asin(sin(-pi))" (asin (sin (- ratpi))) 0.0)1608 (test-equal "sin(0)" (sin 0.0) 0.0)1609 (test-equal "asin(sin(0))" (asin (sin 0.0)) 0.0)1610 (test-equal "sin( 1/4pi)" (sin (/ ratpi 4)) 0.7071067811865476)1611 (test-equal "asin(sin( 1/4pi))" (asin (sin (/ ratpi 4))) (/ pi 4))1612 (test-equal "sin( 1/3pi)" (sin (/ ratpi 3)) 0.8660254037844386)1613 (test-equal "asin(sin( 1/3pi))" (asin (sin (/ ratpi 3))) (/ pi 3))1614 (test-equal "sin( 1/2pi)" (sin (/ ratpi 2)) 1.0)1615 (test-equal "asin(sin( 1/2pi))" (asin (sin (/ ratpi 2))) (/ pi 2))1616 (test-equal "sin( 2/3pi)" (sin (/ (* 2 ratpi) 3)) 0.8660254037844386)1617 (test-equal "asin(sin( 2/3pi))" (asin (sin (/ (* 2 ratpi) 3))) (/ pi 3))1618 (test-equal "sin( 3/4pi)" (sin (* (/ ratpi 4) 3)) 0.7071067811865476)1619 (test-equal "asin(sin( 3/4pi))" (asin (sin (* (/ ratpi 4) 3))) (/ pi 4))1620 (test-equal "sin( pi)" (sin ratpi) 0.0)1621 (test-equal "asin(sin( pi))" (asin (sin ratpi)) 0.0)1622 (test-equal "sin( 3/2pi)" (sin (+ ratpi (/ ratpi 2))) -1.0)1623 (test-equal "asin(sin( 3/2pi))" (asin (sin (+ ratpi (/ ratpi 2)))) (- (/ pi 2)))1624 (test-equal "sin( 4/3pi)" (sin (+ ratpi (/ ratpi 3))) -0.8660254037844386)1625 (test-equal "asin(sin( 4/3pi))" (asin (sin (+ ratpi (/ ratpi 3)))) (- (/ pi 3)))1626 (test-equal "sin( 5/4pi)" (sin (+ ratpi (/ ratpi 4))) -0.7071067811865476)1627 (test-equal "asin(sin( 5/4pi))" (asin (sin (+ ratpi (/ ratpi 4)))) (- (/ pi 4)))1628 (test-equal "sin( 2pi)" (sin (* 2 ratpi)) 0.0)1629 (test-equal "asin(sin( 2pi))" (asin (sin (* 2 ratpi))) 0.0)16301631 (test-equal "tan(-1/3pi)" (tan (- (/ ratpi 3))) -1.7320508075688773)1632 (test-equal "atan(tan(-1/3pi))" (atan (tan (- (/ ratpi 3)))) (- (/ pi 3)))1633 (test-equal "tan(-1/4pi)" (tan (- (/ ratpi 4))) -1.0)1634 (test-equal "atan(tan(-1/4pi))" (atan (tan (- (/ ratpi 4)))) (- (/ pi 4)))1635 ;; NOTE: tan(-(/ pi 2)) should be -inf(?), but isn't. Is that a bug?1636 (test-equal "tan(-pi)" (tan (- ratpi)) 0.0)1637 (test-equal "atan(tan(-pi))" (atan (tan (- ratpi))) 0.0)1638 (test-equal "tan(0)" (tan 0.0) 0.0)1639 (test-equal "atan(tan(0))" (atan (tan 0.0)) 0.0)1640 (test-equal "tan( 1/4pi)" (tan (/ ratpi 4)) 1.0)1641 (test-equal "atan(tan( 1/4pi))" (atan (tan (/ ratpi 4))) (/ pi 4))1642 (test-equal "tan( 1/3pi)" (tan (/ ratpi 3)) 1.7320508075688773)1643 (test-equal "atan(tan( 1/3pi))" (atan (tan (/ ratpi 3))) (/ pi 3))1644 (test-equal "tan( 2/3pi)" (tan (/ (* 2 ratpi) 3)) -1.7320508075688773)1645 (test-equal "atan(tan( 2/3pi))" (atan (tan (/ (* 2 ratpi) 3))) (- (/ pi 3)))1646 (test-equal "tan( 3/4pi)" (tan (* (/ ratpi 4) 3)) -1.0)1647 (test-equal "atan(tan( 3/4pi))" (atan (tan (* (/ ratpi 4) 3))) (- (/ pi 4)))1648 (test-equal "tan( pi)" (tan ratpi) 0.0)1649 (test-equal "atan(tan( pi))" (atan (tan ratpi)) 0.0)1650 (test-equal "tan( 4/3pi)" (tan (+ ratpi (/ ratpi 3))) 1.7320508075688773)1651 (test-equal "atan(tan( 4/3pi))" (atan (tan (+ ratpi (/ ratpi 3)))) (/ pi 3))1652 (test-equal "tan( 5/4pi)" (tan (+ ratpi (/ ratpi 4))) 1.0)1653 (test-equal "atan(tan( 5/4pi))" (atan (tan (+ ratpi (/ ratpi 4)))) (/ pi 4))1654 (test-equal "tan( 2pi)" (tan (* 2 ratpi)) 0.0)1655 (test-equal "atan(tan( 2i))" (atan (tan (* 2 ratpi))) 0.0)16561657 (test-equal "atan2(3, tan(pi))" (atan 3 (tan ratpi)) (/ pi 2))1658 (test-equal "atan2(3, -tan(pi))" (atan 3 (- (tan ratpi))) (/ pi 2))1659 (test-equal "atan2(-3, tan(pi))" (atan -3 (tan ratpi)) (- (/ pi 2)))1660 (test-equal "atan2(-3, -tan(pi))" (atan -3 (- (tan ratpi))) (- (/ pi 2))))))16611662(test-end)16631664;(unless (zero? (test-failure-count)) (exit 1))1665(test-exit)