Fixed bug in (mod 3 5/6).

This commit is contained in:
Abdulaziz Ghuloum 2008-03-22 21:23:51 -04:00
parent ce496aebaf
commit 48a86cbaa3
4 changed files with 27 additions and 7 deletions

View File

@ -2776,9 +2776,14 @@
[(or (fixnum? x) (bignum? x))
(values x 0)]
[else
(let-values ([(a b)
(int-div-and-mod (numerator x) (denominator x))])
(values a (/ b m)))])))
(let ([n0 (numerator x)] [d0 (denominator x)])
(let ([q (quotient n0 d0)])
(let ([r (- n (* q m))])
(if (>= r 0)
(values q r)
(if (> m 0)
(values (- q 1) (+ r m))
(values (+ q 1) (- r m)))))))])))
(cond
[(fixnum? m)
(cond

View File

@ -1 +1 @@
1416
1418

View File

@ -28,7 +28,22 @@
(test +10 +4)
(test +10 -4)
(test -10 +4)
(test -10 -4))
(test -10 -4)
(test +3 +5/6)
(test -3 +5/6)
(test +3 -5/6)
(test -3 -5/6)
(test +3 +7/11)
(test -3 +7/11)
(test +3 -7/11)
(test -3 -7/11)
)
(define (test-div0-and-mod0)

View File

@ -32,9 +32,9 @@
ikptr
ikrt_io_error(){
int err = errno;
#if 0
//#if 0
fprintf(stderr, "errno=%d %s\n", err, strerror(err));
#endif
//#endif
switch(err){
case EBADF : return fix(-2);
case EINTR : return fix(-3);