diff --git a/lib/init-7.scm b/lib/init-7.scm index 48e8a854..d631bd30 100644 --- a/lib/init-7.scm +++ b/lib/init-7.scm @@ -1375,7 +1375,10 @@ (complex (define (real? x) (and (number? x) (not (%complex? x))))) (else (define real? number?))) (define (rational? x) - (and (real? x) (= x x) (not (= x (+ x (if (positive? x) 1 -1)))))) + (and (real? x) + (if (or (> x 1) (< x -1)) + (not (= x (/ x 2))) + (<= -1 x 1)))) (define (eqv? a b) (if (eq? a b) #t (and (number? a) (equal? a b)))) diff --git a/tests/r7rs-tests.scm b/tests/r7rs-tests.scm index 47db3165..258cecae 100644 --- a/tests/r7rs-tests.scm +++ b/tests/r7rs-tests.scm @@ -749,6 +749,9 @@ (test #t (real? #e1e10)) (test #t (real? +inf.0)) (test #f (rational? -inf.0)) +(test #t (rational? 9007199254740991.0)) +(test #t (rational? 9007199254740992.0)) +(test #t (rational? 1.7976931348623157e308)) (test #t (rational? 6/10)) (test #t (rational? 6/3)) (test #t (integer? 3+0i))