[gambit-list] Big number Bug?
Bradley Lucier
lucier at math.purdue.edu
Thu Apr 26 11:47:37 EDT 2007
Here's a fix for the bug. (Marc, can you change this in _num.scm?)
In the directory gambc-4.0b22 do a
make bootstrap
and then replace ##exact-int.div in lib/_num.scm with
(define-prim (##exact-int.div x y)
(cond ((##eq? y 1)
(##cons x 0))
((##eq? y -1)
(##cons (##negate x) 0))
((##eq? x y) ;; can come up in rational arithmetic
(##cons 1 0))
((and (##fixnum? x)
(##fixnum? y))
(##cons (##fixnum.quotient x y) ; note: y can't be -1
(##fixnum.remainder x y)))
(else
(let* ((x-negative? (##negative? x))
(abs-x (if x-negative? (##negate x) x))
(y-negative? (##negative? y))
(abs-y (if y-negative? (##negate y) y)))
(if (##< abs-x abs-y)
(##cons 0 x)
;; at least one of x and y is a bignum, so
;; here abs-x must be a bignum
(let ((result (##bignum.div abs-x abs-y)))
(if (##not (##eq? x-negative? y-negative?))
(##set-car! result (##negate (##car result))))
(if x-negative?
(##set-cdr! result (##negate (##cdr result))))
result))))))
then do a make/make install again. The program now works.
BTW, "display" in gambit does
> (display '(1 2 3 4 5))
12345>
which I presume is not what you want at the end of your test program,
so I suggest you replace "display" with "pretty-print" or "write".
Brad
More information about the Gambit-list
mailing list