* tests/numbers.test ("string->number"): Expect exact rationals
authorMarius Vollmer <mvo@zagadka.de>
Tue, 18 Nov 2003 19:57:30 +0000 (19:57 +0000)
committerMarius Vollmer <mvo@zagadka.de>
Tue, 18 Nov 2003 19:57:30 +0000 (19:57 +0000)
for things like "1/2" and "#e1.2".
("inexact->exact"): Expect overflow error for infs and nans.

* tests/fractions.test: New file from Bill Schottstaedt.  Thanks!

* tests/bit-operations.test (fixnum-bit): Round the result so that
fixnum-bit really is an integer.

test-suite/tests/bit-operations.test
test-suite/tests/fractions.test [new file with mode: 0644]
test-suite/tests/numbers.test

index 95e24fc..4678d1b 100644 (file)
@@ -34,7 +34,7 @@
   (not (not (object-documentation object))))
 
 (define fixnum-bit
-  (inexact->exact (+ (/ (log (+ most-positive-fixnum 1)) (log 2)) 1)))
+  (inexact->exact (round (+ (/ (log (+ most-positive-fixnum 1)) (log 2)) 1))))
 
 (define fixnum-min most-negative-fixnum)
 (define fixnum-max most-positive-fixnum)
diff --git a/test-suite/tests/fractions.test b/test-suite/tests/fractions.test
new file mode 100644 (file)
index 0000000..2e7e05e
--- /dev/null
@@ -0,0 +1,390 @@
+(define-module (test-suite test-fractions)
+  #:use-module (test-suite lib)
+  #:use-module (ice-9 documentation)
+  #:use-module (oop goops))
+
+(defmacro test= (a b)
+  `(pass-if ,(format #f "(= ~A ~A)" a b) (= ,a ,b)))
+
+(defmacro testeqv (a b)
+  `(pass-if ,(format #f "(eqv? ~A ~A)" a b) (eqv? ,a ,b)))
+
+(defmacro testeq (a b)
+  `(pass-if ,(format #f "(eq? ~A ~A)" a b) (eq? ,a ,b)))
+
+(defmacro teststr= (a b)
+  `(pass-if ,(format #f "(string=? ~A ~A)" a b) (string=? ,a ,b)))
+
+(with-test-prefix "fractions"
+
+  (test= 3/4 .75)
+  (test= 3000000000000/4000000000000 .75)
+  (test= .75 3/4)
+  (test= .75 3000000000000/4000000000000)
+  (testeqv 3/4 6/8)
+  (testeqv 3/4 3000000000000/4000000000000)
+  (testeqv 3 3/1)
+  (test= 1/3 (/ 1.0 3.0))
+  (testeqv (+ 1/4 1/2) 3/4)
+  (testeqv (* 1/4 2/3) 1/6)
+  (testeqv (/ 1/4 2/3) 3/8)
+  (testeqv (+ 1/4 2/3) 11/12)
+  (testeqv (- 1/4 2/3) -5/12)
+  (test= -3/4 -.75)
+  (testeqv -3/4 -6/8)
+  (testeqv -3/4 (/ 1/2 -2/3))
+  (testeqv (* 3/4 2) 3/2)
+  (testeqv (* 2 3/4) 3/2)
+  (testeqv (* 3/4 0.5) .375)
+  (testeqv (* 0.5 3/4) .375)
+  (testeqv (* 1/2 2-4i) 1-2i)
+  (testeqv (* 2-4i 1/2) 1-2i)
+  (testeqv (* 1/2 2+3i) 1+1.5i)
+  (testeqv (/ 2+4i 1/2) 4+8i)
+  (test= 1/2 0.5+0i)
+  (testeqv (- 1/2 0.5+i) -i)
+  (testeqv (- 0.5+i 1/2) +i)
+  (testeqv (+ 1/2 0.5+i) 1+i)
+  (testeqv (+ 0.5+i 1/2) 1+i)
+  (testeq (> 1 2/3) #t)
+  (testeq (> 2/3 1) #f)
+  (testeq (> 1.5 2/3) #t)
+  (testeq (> 2/3 1.5) #f)
+  (testeq (> 3/4 2/3) #t)
+  (testeq (> 2/3 3/4) #f)
+  (testeqv (max 1 2/3) 1)
+  (testeqv (max 2/3 1) 1)
+  (testeqv (max 1 4/3) 4/3)
+  (testeqv (max 4/3 1) 4/3)
+  (testeqv (max 1.5 4/3) 1.5)
+  (testeqv (max 4/3 1.5) 1.5)
+  (testeqv (max 4/3 2/3) 4/3)
+  (testeqv (max 2/3 4/3) 4/3)
+  (testeqv (min 1 2/3) 2/3)
+  (testeqv (min 2/3 1) 2/3)
+  (testeqv (min 1 4/3) 1)
+  (testeqv (min 4/3 1) 1)
+  (testeqv (min 1.5 1/2) 0.5)
+  (testeqv (min 1/2 1.5) 0.5)
+  (testeqv (min 4/3 2/3) 2/3)
+  (testeqv (min 2/3 4/3) 2/3)
+  (testeq (> 3/4 12345678912345678) #f)
+  (testeq (> 12345678912345678 3/4) #t)
+  (testeq (< 3/4 12345678912345678) #t)
+  (testeq (< 12345678912345678 3/4) #f)
+  (testeqv (max 12345678912345678 3/4) 12345678912345678)
+  (testeqv (max 3/4 12345678912345678) 12345678912345678)
+  (testeqv (min 12345678912345678 3/4) 3/4)
+  (testeqv (min 3/4 12345678912345678) 3/4)
+  (testeqv (max 3/4 10197734562406803221/17452826108659293487) 3/4)
+  (testeqv (max 1/2 10197734562406803221/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (min 3/4 10197734562406803221/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (min 1/2 10197734562406803221/17452826108659293487) 1/2)
+  (testeqv (max 10197734562406803221/17452826108659293487 10197734562406803221/17) 10197734562406803221/17)
+  (testeqv (max 10197734562406803221/174 10197734562406803221/17452826108659293487) 10197734562406803221/174)
+  (testeqv (max 10/17452826108659293487 10197734562406803221/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (max 10197734562406803221/17452826108659293487 10/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (min 10197734562406803221/17452826108659293487 10197734562406803221/17) 10197734562406803221/17452826108659293487)
+  (testeqv (min 10197734562406803221/174 10197734562406803221/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (min 10/17452826108659293487 10197734562406803221/17452826108659293487) 10/17452826108659293487)
+  (testeqv (min 10197734562406803221/17452826108659293487 10/17452826108659293487) 10/17452826108659293487)
+  (testeqv (expt 2 1/2) (sqrt 2))
+  (testeqv (expt 1/2 2) 1/4)
+  (testeqv (expt 2.0 1/2) (sqrt 2))
+  (testeqv (expt 1/2 2.0) 1/4)
+  (testeqv (real-part 3/4) .75)
+  (testeqv (imag-part 3/4) 0)
+  (testeqv (numerator 3/4) 3)
+  (testeqv (denominator 3/4) 4)
+  (testeqv (numerator -3/4) -3)
+  (testeqv (denominator -3/4) 4)
+  (testeqv (numerator 10197734562406803221/17452826108659293487) 10197734562406803221)
+  (testeqv (denominator 10197734562406803221/17452826108659293487) 17452826108659293487)
+  (testeqv (numerator 1/17452826108659293487) 1)
+  (testeqv (denominator 10197734562406803221/17) 17)
+  (testeq (rational? 3/4) #t)
+  (testeq (rational? 1.5) #t)
+  (testeq (rational? 1) #t)
+  (testeq (rational? 10197734562406803221/17452826108659293487) #t)
+  (testeq (integer? 8/4) #t)
+  (testeq (rational? 6/3) #t)
+  (testeqv (angle 3/4) 0.0)
+  (testeqv (angle -3/4) (atan 0.0 -1.0))
+  (testeqv (angle 10197734562406803221/17452826108659293487) 0.0)
+  (testeqv (magnitude 3/4) 3/4)
+  (testeqv (magnitude -3/4) 3/4)
+  (testeqv (magnitude 10197734562406803221/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (magnitude -10197734562406803221/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (abs 3/4) 3/4)
+  (testeqv (abs -3/4) 3/4)
+  (testeqv (abs 10197734562406803221/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (abs -10197734562406803221/17452826108659293487) 10197734562406803221/17452826108659293487)
+  (testeqv (abs 10197734562406803221/174) 10197734562406803221/174)
+  (testeqv (abs -10197734562406803221/174) 10197734562406803221/174)
+  (testeqv (abs 101/17452826108659293487) 101/17452826108659293487)
+  (testeqv (abs -101/17452826108659293487) 101/17452826108659293487)
+  (testeqv (exact->inexact 3/4) .75)
+  (testeqv (inexact->exact .3) 3/10)
+  (testeqv (inexact->exact -.3) -3/10)
+  (testeqv (inexact->exact .33) 33/10)
+  (testeq (< (- (exact->inexact 10197734562406803221/17452826108659293487) .584302765576009) .0000001) #t)
+  (testeqv (rationalize .76 .1) 3/4)
+  (testeqv (rationalize .723 .1) 2/3)
+  (testeqv (rationalize .723 .01) 5/7)
+  (testeqv (rationalize -.723 .01) -5/7)
+  (testeqv (rationalize 10.2 .01) 51/5)
+  (testeqv (rationalize -10.2 .01) -51/5)
+  (testeqv (rationalize 10197734562406803221/17452826108659293487 .1) 1/2)
+  (testeqv (rationalize 10197734562406803221/17452826108659293487 .01) 7/12)
+  (testeqv (rationalize 10197734562406803221/17452826108659293487 .001) 7/12)
+  (testeqv (rationalize 10197734562406803221/17452826108659293487 .0001) 52/89)
+  (testeqv (rationalize 3/10 1/10) 1/3)
+  (testeqv (rationalize 3/10 -1/10) 1/3)
+  (testeqv (rationalize -3/10 1/10) -1/3)
+  (testeqv (rationalize -3/10 -1/10) -1/3)
+  (testeqv (rationalize 3/10 4/10) 0)
+  (testeqv (rationalize .3 4/10) 0)
+  (testeqv (rationalize .3 0.0) 3/10)
+  (testeqv (rationalize -.3 0.0) -3/10)
+  (testeqv (rationalize .12345 0.0) 2469/2000)
+  (testeqv (rationalize 10.3 0.0) 103/10)
+  (testeq (exact? #i2/3) #f)
+  (testeq (exact? -15/16) #t)
+  (testeq (exact? (/ 2 3)) #t)
+  (testeq (exact? (/ 3000000000000 4000000000000)) #t)
+  (testeq (exact? (/ 3 4000000000)) #t)
+  (testeq (exact? (/ 4000000000 3)) #t)
+  (testeq (exact? (/ 10197734562406803221 17452826108659293487)) #t)
+  (testeq (exact? (/ 10197734562406803221 17)) #t)
+  (testeq (inexact? #i2/3) #t)
+  (testeq (inexact? -15/16) #f)
+  (testeq (inexact? (/ 2 3)) #f)
+  (testeq (inexact? (/ 3000000000000 4000000000000)) #f)
+  (testeq (inexact? (/ 3 4000000000)) #f)
+  (testeq (inexact? (/ 4000000000 3)) #f)
+  (testeq (inexact? (/ 10197734562406803221 17452826108659293487)) #f)
+  (testeq (inexact? (/ 10197734562406803221 17)) #f)
+  (testeq (= 2/3 .667) #f)
+  (testeq (< 1/2 2/3 3/4) #t)
+  (testeqv (+ 1/2 2/3) 7/6)
+  (testeqv (* 4 1/2) 2)
+  (testeqv (- -2/3) 2/3)
+  (testeqv (- 2/3) -2/3)
+  (testeqv (+ 2/3) 2/3)
+  (testeqv (* 2/3) 2/3)
+  (testeqv (/ 2/3) 3/2)
+  (testeqv (/ 3 4 5) 3/20)
+  (testeqv (* 1 1/2) 1/2)
+  (testeqv (+ 1 1/4 1/3) 19/12)
+  (testeqv (* 3/5 1/6 3) 3/10)
+  (testeqv 0/3 0)
+  (testeqv (1- 1/2) 1/2)
+  (testeqv (1+ 1/2) 3/2)
+  (testeq (zero? 3/4) #f)
+  (testeq (zero? 0/4) #t)
+  (testeq (positive? 3/4) #t)
+  (testeq (negative? 3/4) #f)
+  (testeq (positive? 10197734562406803221/17452826108659293487) #t)
+  (testeq (negative? 10197734562406803221/17452826108659293487) #f)
+  (testeqv (/ 17) 1/17)
+  (testeqv (/ 17452826108659293487) 1/17452826108659293487)
+  (testeqv (/ -17) -1/17)
+  (testeqv (/ -17452826108659293487) -1/17452826108659293487)
+  (testeqv (/ 1/2) 2)
+  (testeqv (/ 2 3) 2/3)
+  (testeqv (/ 2 -3) -2/3)
+  (testeq (zero? (+ 1/2 1/2)) #f)
+  (testeq (zero? (+ 1/2 -1/2)) #t)
+  (testeq (zero? (- 1/2 1/2)) #t)
+  (testeqv (/ 60 5 4 3 2) 1/2)
+  (test= (truncate 5/4) 1.0)
+  (test= (truncate 4/5) 0.0)
+  (test= (truncate -2/3) 0.0)
+  (test= (truncate 10197734562406803221/17452826108659293487) 0.0)
+  (test= (truncate 17452826108659293487/10197734562406803221) 1.0)
+  (test= (/ (log 1/2) (log 2)) -1.0)
+  (test= (floor 2/3) 0)
+  (test= (floor -2/3) -1)
+  (test= (floor 10197734562406803221/17452826108659293487) 0)
+  (test= (ceiling 2/3) 1)
+  (test= (ceiling -2/3) 0)
+  (test= (ceiling 10197734562406803221/17452826108659293487) 1)
+  (test= (round 2/3) 1.0)
+  (test= (round -2/3) -1.0)
+  (test= (round 1/3) 0.0)
+  (test= (round 10197734562406803221/17452826108659293487) 1.0)
+  (testeqv (max 1/2 3/4 4/5 5/6 6/7) 6/7)
+  (testeqv (min 1/2 3/4 4/5 5/6 6/7) 1/2)
+  (testeqv (expt -1/2 5) -1/32)
+  (testeqv (expt 1/2 -10) 1024)
+  (testeqv (rationalize .3 1/10) 1/3)
+  (test= (make-rectangular 1/2 -1/2) 0.5-0.5i)
+  (test= (sqrt 1/4) 0.5)
+  (testeqv (string->number "3/4") 3/4)
+  (testeqv (string->number "-3/4") -3/4)
+  (testeqv (string->number "10197734562406803221/17452826108659293487") 10197734562406803221/17452826108659293487)
+  (testeqv (string->number "-10197734562406803221/17452826108659293487") -10197734562406803221/17452826108659293487)
+  (testeqv (string->number "10/17452826108659293487") 10/17452826108659293487)
+  (testeqv (string->number "10197734562406803221/174") 10197734562406803221/174)
+  (teststr= (number->string 3/4) "3/4")
+  (teststr= (number->string 10197734562406803221/17452826108659293487) "10197734562406803221/17452826108659293487")
+  (testeq (eq? 3/4 .75) #f)
+  (testeq (eqv? 3/4 .75) #f)
+  (testeq (eqv? 3/4 3/4) #t)
+  (testeq (eqv? 10197734562406803221/17452826108659293487 10197734562406803221/17452826108659293487) #t)
+  (testeq (equal? 3/4 .75) #t)
+  (testeq (number? 3/4) #t)
+  (testeq (real? 3/4) #t)
+  (testeq (integer? 3/4) #f)
+  (test= (* 1/2 2.0e40) 1.0e40)
+  (test= (* 2.0e40 1/2) 1.0e40)
+  (test= (/ 3.0e40 3/2) 2.0e40)
+  (testeqv (case 1/2 ((1/2) 1) ((3/4) 2)) 1)
+  (testeqv (/ 1 -2) -1/2)
+  (testeqv (numerator (/ 1 -2)) -1)
+  (testeqv (denominator (/ 1 -2)) 2)
+  (testeq (negative? (/ 1 -2)) #t)
+  (testeq (positive? (/ 1 -2)) #f)
+  (testeqv (/ -1/2 -1/3) 3/2)
+  (testeqv (numerator (/ -1/2 -1/3)) 3)
+  (testeqv (denominator (/ -1/2 -1/3)) 2)
+  (testeq (negative? (/ -1/2 -1/3)) #f)
+  (testeq (positive? (/ -1/2 -1/3)) #t)
+  (testeqv (numerator 12) 12)
+  (testeqv (numerator -12) -12)
+  (testeqv (denominator 12) 1)
+  (testeqv (denominator -12) 1)
+  (testeqv (- 1/2 1/2) 0)
+  (testeqv (+ 1/2 1/2) 1)
+  (testeqv (/ 1/2 1/2) 1)
+  (testeqv (* 2/1 1/2) 1)
+  (testeq (complex? 1/2) #t)
+  (testeqv (+ (exact->inexact 3/10) (exact->inexact -3/10)) 0.0)
+  (testeqv (/ 1/2 1/4) 2)
+  (testeqv (/ 2 1/4) 8)
+  (testeqv (/ 1/4 2) 1/8)
+  (testeqv (ash 1/2 0) 1/2)
+  (testeqv (ash 1/2 1) 1)
+  ;;(testeqv (ash 1/2 -1) 1/4)
+
+  (testeqv (floor 5/2) 2)
+  (testeqv (ceiling 5/2) 3)
+  (testeqv (round 5/2) 2)
+  (testeqv (truncate 5/2) 2)
+  (testeqv (floor -5/2) -3)
+  (testeqv (ceiling -5/2) -2)
+  (testeqv (round -5/2) -2)
+  (testeqv (truncate -5/2) -2)
+  (testeqv (floor 4/3) 1)
+  (testeqv (ceiling 4/3) 2)
+  (testeqv (round 4/3) 1)
+  (testeqv (truncate 4/3) 1)
+  (testeqv (floor -4/3) -2)
+  (testeqv (ceiling -4/3) -1)
+  (testeqv (round -4/3) -1)
+  (testeqv (truncate -4/3) -1)
+  (testeqv (floor 5/3) 1)
+  (testeqv (ceiling 5/3) 2)
+  (testeqv (round 5/3) 2)
+  (testeqv (truncate 5/3) 1)
+  (testeqv (floor -5/3) -2)
+  (testeqv (ceiling -5/3) -1)
+  (testeqv (round -5/3) -2)
+  (testeqv (truncate -5/3) -1)
+  (testeqv (floor 11/4) 2)
+  (testeqv (ceiling 11/4) 3)
+  (testeqv (round 11/4) 3)
+  (testeqv (truncate 11/4) 2)
+  (testeqv (floor -11/4) -3)
+  (testeqv (ceiling -11/4) -2)
+  (testeqv (round -11/4) -3)
+  (testeqv (truncate -11/4) -2)
+  (testeqv (floor 9/4) 2)
+  (testeqv (ceiling 9/4) 3)
+  (testeqv (round 9/4) 2)
+  (testeqv (truncate 9/4) 2)
+  (testeqv (floor -9/4) -3)
+  (testeqv (ceiling -9/4) -2)
+  (testeqv (round -9/4) -2)
+  (testeqv (truncate -9/4) -2)
+
+  ;; from Dybvig
+  (testeqv (numerator 9.0) 9.0)
+  (testeqv (numerator 9) 9)
+  (testeqv (numerator -9/4) -9)
+  (testeqv (numerator -2.25) -9.0) ; -9/4!
+  (testeqv (denominator 0) 1)
+  (testeqv (denominator 9) 1)
+  (testeqv (denominator 2/3) 3)
+  (testeqv (denominator -9/4) 4)
+  (testeqv (denominator -2.25) 4.0)
+  (testeqv (denominator 9.0) 1.0)
+  (testeqv (expt 2 -2) 1/4)
+  (testeqv (expt 1/2 2) 1/4)
+  (testeqv (expt 1/2 -2) 4)
+  (testeqv (expt -1/2 3) -1/8)
+
+
+
+  ;; from (GPL'd) Clisp tests
+  (test= (+ 1 1/2 0.5 3.0+5.5i) 5.0+5.5i)
+  (testeq (let ((error (catch #t (lambda () (/ 1 0)) (lambda args (car args))))) error) 'numerical-overflow)
+  (testeq (let ((error (catch #t (lambda () (/ 0)) (lambda args (car args))))) error) 'numerical-overflow)
+  (testeq (let ((error (catch #t (lambda () (modulo 1/2 1)) (lambda args (car args))))) error) 'wrong-type-arg)
+  (testeq (let ((error (catch #t (lambda () (logand 1/2 1)) (lambda args (car args))))) error) 'wrong-type-arg)
+  (testeq (let ((error (catch #t (lambda () (gcd 1/2 3)) (lambda args (car args))))) error) 'wrong-type-arg)
+  (testeq (let ((error (catch #t (lambda () (numerator 1+i)) (lambda args (car args))))) error) 'wrong-type-arg)
+  (test= (- 0+6i 1/4 0.5 7) -7.75+6.0i)
+  (testeqv (rationalize 2.5 .001) 5/2)
+  (testeqv (rationalize 7/3 .001) 7/3)
+  (testeqv (rationalize 3.14159265 .1) 22/7)
+  (testeqv (numerator (/ 8 -6)) -4)
+  (testeqv (denominator (/ 8 -6)) 3)
+  (testeqv (gcd (numerator 7/9) (denominator 7/9)) 1)
+  (testeqv (/ 10105597264942543888 14352488138967388642) 5052798632471271944/7176244069483694321)
+  (testeqv (/ -17631701977702695093 3931860028646338313) -17631701977702695093/3931860028646338313)
+  (testeqv (/ -1606495881715082381 16324360910828438638) -1606495881715082381/16324360910828438638)
+  (testeqv (/ -7960193178071300653 -10280747961248435844) 7960193178071300653/10280747961248435844)
+  (testeqv (+ -6069217517368004039/4076344942716985944 -399587800008780737/578697755310708616) -321318766345655960630110128852941297/147435729263904928853096856396980844)
+  (testeqv (+ -41285036778370718/305793940074617155 -1396094619926552183/15846027887642356854) -1081121118676718273499338028514700537/4845619302294419132297197085940230370)
+  (testeqv (+ 15975644088444536091/18063939613598316583 17501188199168431305/2979264551795273683) 363736076920798535449296038324193823968/53817254956563877935003279344562385189)
+  (testeqv (+ 10197734562406803221/17452826108659293487 14639450560606090654/236781760961536951) 257914422508077920978698094723491089669/4132510899763835955061848877304138137)
+  (testeqv (+ 2479135971595944301/28169711053558469409458629766960029324030958129245230797895768033968717159836 3427244662960653095/28446538857424788738244844756675951434179713170118835630969510829753715142438) 83533664807147783700314944003289704497366290621039272787320536148072960487262393639109696219129/400665390043739792096386856839000624247597803909916773326187593475005945995926511155915226239317839405221783416485999405286913042389632370302962776360084)
+  (testeqv (+ 14865500635281371370/56222262470894935247131881777606182311286871927285650835673424014252462156319 6436092572090050725/19282524131572095520593158313261757267758159099923763177708581262473988426947) 648496060602737474174747620183913927791943082591316359990137585798909535115053578637078811588665/1084107132826611778585714784136700465449309125114745313342842325649687943726086785657821763235618936882528385000712567133180567926723616940173290425928093)
+  (testeqv (+ 340196811925805824067049620503247332111/14422464039094716975 51285507111580975533385007190438537498/3230944134273302873) 1838820276033673324738967436225477772648372110186756083453/46598175588880723338390245118389369175)
+  (testeqv (+ -210449319160504160992731982827917332322/5436857856220342451 251628249079137248539965770847855056283/4323109210037952829) 458271632943884346915405609513071881239303671882386130695/23504130271893362375786510953364243879)
+  (testeqv (- 8229768172162771789/4094631553683915058 14916542302144281688/9648520391570031013) 18327341244785642013243791303754634353/39507136041685332578233153660317693754)
+  (testeqv (- 13554976081719376860/5850035209629724601 -6813034992928443315/16012083383654426278) 256899901877002811987490932642058619395/93671251573905451634945335611797465078)
+  (testeqv (- -221798849980968127/896588178875000428 -10118632981534633697/16809799818197706916) 333990778095757160537366868413422249/941966737890699707694484674257410003)
+  (testeqv (- -10398409463665680242/10672871071680021919 908300169382593227/1663860017749090135) -2076589873614048366639515256135965791/1366012573135328609279238070700513005)
+  (testeqv (- -2198518713248421187/494031967775171833 162489257999262168/3608560229859558061) -8013762081101965644053022173225152351/1782744111192743850497670941715295813)
+  (testeqv (- 4025149216228566945/640594137312937394 5467380276809034025/15813352732084653151) 60148732603712157399679443099667862845/10129941051434949990590527231467828494)
+  (testeqv (- 1543899448831604569141696144740105016328586790221799945430718394112623114412/1094690716976737526626281319975432667416762320123576900412499904933271786567 -101835025746074730017715423582062511397387458863000475669454309217160145993/55116548932808468782187525862059393507883043749327746382569396580129398962) 196572266866178229534134252625134989714563665559807019513454337864363053729628560611312158082929567528955985669620113192156991984486011150099776316375/60335574468539540262844259780498204139853746803235564167348945699931512713417761400790104247218084745081610815218855896912895393599203789305655343454)
+  (testeqv (- -37581128364300495505521143552535972339959603365602244668159915869829949338997/42947503543372015019662104425995959382231280059683481488692141811517675950053 -64888994735350842409379226446854438865448614840503930577860382883594178287934/83188698741706753136718468601650233481619465918167616089202536622553688681087) -339504834548876267781536981106771553482515399809961247195394672491113984585270709765073243997043174508213253440272888923497173265137136111635177948889237/3572746933977957867604303713153220827104741303667912510494658617478381525690274918494624922428110123336345510454960178899375325287131764283538305257747611)
+  (testeqv (* -6520062188352981842/3213004995534018829 -3812444292971845716/15284944374811818089) 24857373879807849010516976362973488872/49110602632729971801355498746248797781)
+  (testeqv (* -844583948128454879/4750740551331102615 -1309778567130405125/4885884698278749707) 221243590680205607733892613510570975/4642314113048197066962569716783636761)
+  (testeqv (* -4579815856418431271/16947444571374397297 7990245706938186906/12540719430158043191) -36593853985314806270746820601513137526/212533147427761354206383017714519654727)
+  (testeqv (* -3587966953201943536/3194797554208122281 975954052071387816/2707062718507963111) -3501690886675668292903668827990357376/8648517352177231144330968693325176191)
+  (testeqv (* 710265334225408429/567023629756400552 -5578988760400430103/4131535930210536898) -3962562316545608552741467762441538187/2342678499616965424161446427863567696)
+  (testeqv (* 18305319006789031727/4480148641441744463 -1641093267260986094/16028097657311023719) -30040735777106040963634910981471804338/71808259944297590021537032075729917897)
+  (testeqv (* 522499067029593907/142530390958606446621834761330018829110 1567459634764499377/31663510497342378306792964160850079086) 818996196770998943862055820464495939/4513012530308148429025282037949729145117603192483641232823845248212618993460)
+  (testeqv (* -280037880297253633994139513185953058494/23798550327416056573646642830182072429 13967268482262630670960486883264178489/7947215947745048068401387767511847243) -434596028812829556627014314125713048434599389957141408329542154357763726174/21014690966139335562014814134594464675233042588696546668504776333756662583)
+  (testeqv (* 87160410649223805266866345018804635271/204719779683096591635231158476535039583 91197762560765392928084914476898132964/277206223024759381433146631560580134513) 7948834435086720002947247338196997812861466884983039250681993725808882173244/56749596904412078223459353928850191672356004665473536520452927516595919428079)
+  (testeqv (/ 7013212896988366906/12397903473277899947 818833870013215068/2125577647443895255) 7453564285301859120853045020886215515/5075911640537211768265804260348400698)
+  (testeqv (/ -15781329068048599432/14942574238341613337 4388772934226358350/2640112802717985697) -20832244458230302534551181278529162052/32789782692450857054331267544650656975)
+  (testeqv (/ -9015230453321124271/17425619133302730035 -10422000746814766599/14972344381173680534) 134979135022768387806775446187867640714/181609815620990738305316999098032100965)
+  (testeqv (/ -14741075237791868512/12448692140900938227 -1090381863721238817/1060836378253796023) 15637868866825840780217685066084527776/13573828137487503515304766902031557459)
+  (testeqv (/ -7371815071140740177/4722722556038701367 3872455829192658988/994203944294825175) -7329087620340161131469364260313555975/18288534491791723206480607737200436596)
+  (testeqv (/ -9856364379969390509/7988230468709836259 -7208901117187058135/7430860779232874136) 1093153305924514768551484985555671272/859497963436269188803272225817371895)
+  (testeqv (/ -4420263280205408439/38682162086456801604593696710774835436326970692840048042132553053971380151628 -758651402628235427/1755534012040040367913026343944696058732638465867705260088080517539506722166) 3879961265286134914514096239640695384126081133972137242327715997675029567458817030555062379437/14673138261791601182714628661554161812345431143865809776872034934342213839184709418896670662578)
+  (testeqv (/ -54987418627898620923060954379316763081930842855917193391807940070173620336071/17370345837184638879794373707261631548922174314274224219546763452439685451597 107349939397731511365417710412808670916754334908520065561311453951414109180973/7800708635318451621630266369706695626474649690647985662113853436261704078874) -428940831324519456770429889832838610542119304716244392653623661175655561457214418178921042544524225772650432309479656622489393939407340321261255371264054/1864705572939408818246392762570376592749103793151936455808919833872532407312841098160841844995663367019074328670998871082130543124576872890789577304863881))
+;; end clisp borrowings
+
+(define-generic G)
+(define-method (G (a <integer>)) 'integer)
+(define-method (G (a <fraction>)) 'fraction)
+
+(with-test-prefix "fraction generics"
+  (testeq (G 1) 'integer)
+  (testeq (G 2/3) 'fraction))
+
index b2920a2..9e707d2 100644 (file)
     (for-each (lambda (couple)
                 (apply
                  (lambda (x y)
-                   (let ((x (string->number x)))
-                     (if (or (eq? x #f) (not (eqv? x y))) (throw 'fail))))
+                   (let ((xx (string->number x)))
+                     (if (or (eq? xx #f) (not (eqv? xx y)))
+                        (throw 'fail))))
                  couple))
               `(;; Radix:
                 ("#b0" 0) ("#B0" 0) ("#b1" 1) ("#B1" 1) ("#o0" 0) ("#O0" 0)
                 ("#d1234567890" 1234567890)
                 ("#x1234567890abcdef" 1311768467294899695)
                 ;; Exactness:
-                ("#e1" 1) ("#e1.2" 1) ("#i1.1" 1.1) ("#i1" 1.0)
+                ("#e1" 1) ("#e1.2" ,(inexact->exact 1.2))
+               ("#i1.1" 1.1) ("#i1" 1.0)
                 ;; Integers:
                 ("1" ,(1+ 0)) ("23" ,(+ 9 9 5)) ("-1" ,(- 0 1)) 
                 ("-45" ,(- 0 45)) ("2#" 20.0) ("2##" 200.0) ("12##" 1200.0)
                 ("#b#i100" 4.0)
-                ;; Rationals:
-                ("1/1" 1) ("1/2" 0.5) ("-1/2" -0.5) ("1#/1" 10.0)
-                ("10/1#" 1.0) ("1#/1#" 1.0) ("#e9/10" 1) ("#e10/1#" 1)
+                ;; Fractions:
+                ("1/1" 1) ("1/2" 1/2) ("-1/2" -1/2) ("1#/1" 10.0)
+                ("10/1#" 1.0) ("1#/1#" 1.0) ("#e9/10" 9/10) ("#e10/1#" 1)
                 ("#i6/8" 0.75) ("#i1/1" 1.0)
                 ;; Decimal numbers:
                 ;; * <uinteger 10> <suffix>
 
 (with-test-prefix "inexact->exact"
   
-  (pass-if-exception "+inf" exception:numerical-overflow
+  (pass-if-exception "+inf" exception:out-of-range
     (inexact->exact +inf.0))
   
-  (pass-if-exception "-inf" exception:numerical-overflow
+  (pass-if-exception "-inf" exception:out-of-range
     (inexact->exact -inf.0))
   
-  (pass-if-exception "nan" exception:numerical-overflow
+  (pass-if-exception "nan" exception:out-of-range
     (inexact->exact +nan.0))
   
   (with-test-prefix "2.0**i to exact and back"