srfi-19: Fix `string->date' weekday lookup.
[bpt/guile.git] / test-suite / tests / fractions.test
index 2e7e05e..0e1a4d6 100644 (file)
@@ -1,3 +1,20 @@
+;;;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+;;;;
+;;;; This program is free software; you can redistribute it and/or modify
+;;;; it under the terms of the GNU General Public License version 2 as
+;;;; published by the Free Software Foundation; see file GNU-GPL.
+;;;;
+;;;; This program is distributed in the hope that it will be useful,
+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;;; GNU General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU General Public License
+;;;; along with this program; if not, write to the Free Software Foundation,
+;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+;;;; Based in part on code from GNU CLISP, Copyright (C) 1993 Michael Stoll
+
 (define-module (test-suite test-fractions)
   #:use-module (test-suite lib)
   #:use-module (ice-9 documentation)
   (testeqv 3/4 6/8)
   (testeqv 3/4 3000000000000/4000000000000)
   (testeqv 3 3/1)
-  (test= 1/3 (/ 1.0 3.0))
+
+  (test= -1 (/ most-negative-fixnum (- most-negative-fixnum)))
+  (testeq #t (integer? (/ most-negative-fixnum (- most-negative-fixnum))))
+
   (testeqv (+ 1/4 1/2) 3/4)
   (testeqv (* 1/4 2/3) 1/6)
   (testeqv (/ 1/4 2/3) 3/8)
   (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 (expt 1/2 2) 1/4)
+  (testeqv (real-part 3/4) 3/4)
   (testeqv (imag-part 3/4) 0)
   (testeqv (numerator 3/4) 3)
   (testeqv (denominator 3/4) 4)
   (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 (inexact->exact .5) 1/2)
+  (testeqv (inexact->exact -.5) -1/2)
+  (testeqv (inexact->exact (exact->inexact 2135445/16777216)) 2135445/16777216)
+  (testeq (< (- (exact->inexact 10197734562406803221/17452826108659293487)
+               .584302765576009) .0000001) #t)
+  (testeqv (rationalize #e0.76 1/10) 3/4)
+  (testeqv (rationalize #e0.723 1/10) 2/3)
+  (testeqv (rationalize #e0.723 1/100) 5/7)
+  (testeqv (rationalize #e-0.723 1/100) -5/7)
+  (testeqv (rationalize #e10.2 1/100) 51/5)
+  (testeqv (rationalize #e-10.2 1/100) -51/5)
+  (testeqv (rationalize 10197734562406803221/17452826108659293487 1/10) 1/2)
+  (testeqv (rationalize 10197734562406803221/17452826108659293487 1/100) 7/12)
+  (testeqv (rationalize 10197734562406803221/17452826108659293487 1/1000) 7/12)
+  (testeqv (rationalize 10197734562406803221/17452826108659293487 1/10000) 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)
   (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) -1/2)
   (testeqv (1+ 1/2) 3/2)
   (testeq (zero? 3/4) #f)
   (testeq (zero? 0/4) #t)
   (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)
+  (testeqv (rationalize #e.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)
   (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 (equal? 3/4 .75) #f)
   (testeq (number? 3/4) #t)
   (testeq (real? 3/4) #t)
   (testeq (integer? 3/4) #f)
   (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)
   (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 (rationalize #e2.5 1/1000) 5/2)
+  (testeqv (rationalize 7/3 1/1000) 7/3)
+  (testeqv (rationalize #e3.14159265 1/10) 22/7)
   (testeqv (numerator (/ 8 -6)) -4)
   (testeqv (denominator (/ 8 -6)) 3)
   (testeqv (gcd (numerator 7/9) (denominator 7/9)) 1)