mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
Fix border case in bignum division when the estimate gives a zero
remainder immediately after having overshot the previous estimate. Fixes issue #303.
This commit is contained in:
parent
3e9092cfcc
commit
47381d8802
2 changed files with 10 additions and 1 deletions
3
bignum.c
3
bignum.c
|
@ -568,7 +568,8 @@ sexp sexp_bignum_quot_rem (sexp ctx, sexp *rem, sexp a, sexp b) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* adjust signs */
|
/* adjust signs */
|
||||||
if (sign < 0) {
|
a1 = sexp_bignum_normalize(a1);
|
||||||
|
if (sign < 0 && a1 != SEXP_ZERO) {
|
||||||
q = sexp_sub(ctx, q, SEXP_ONE);
|
q = sexp_sub(ctx, q, SEXP_ONE);
|
||||||
a1 = sexp_add(ctx, a1, b1);
|
a1 = sexp_add(ctx, a1, b1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,5 +337,13 @@
|
||||||
(let ((r (/ (expt 2 61) 3)))
|
(let ((r (/ (expt 2 61) 3)))
|
||||||
(test 0 (- r r))
|
(test 0 (- r r))
|
||||||
(test 2305843009213693952/3 r))
|
(test 2305843009213693952/3 r))
|
||||||
|
(let ((x (+ (expt 2 32) +2))
|
||||||
|
(y (+ (expt 2 32) -1)))
|
||||||
|
(test 0(remainder (* x y) y))
|
||||||
|
(test 0(remainder (* x y) x)))
|
||||||
|
(let ((x (+ (expt 2 64) +2))
|
||||||
|
(y (+ (expt 2 64) -1)))
|
||||||
|
(test 0(remainder (* x y) y))
|
||||||
|
(test 0(remainder (* x y) x)))
|
||||||
|
|
||||||
(test-end))))
|
(test-end))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue