mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
fixing bitwise-xor for negative bignum cases
This commit is contained in:
parent
bddb28ace7
commit
cb7eaa7fe6
2 changed files with 9 additions and 2 deletions
|
@ -131,9 +131,9 @@ sexp sexp_bit_ior (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp y) {
|
|||
sexp_set_twos_complement(res);
|
||||
for (i=0; i<len; i++)
|
||||
sexp_bignum_data(res)[i] |= sexp_bignum_data(tmp)[i];
|
||||
if ((sexp_bignum_sign(res) < 0) ^ sexp_fixnump(y))
|
||||
if ((sexp_bignum_sign(x) < 0) ^ (sexp_fixnump(y) || sexp_bignum_sign(y) < 0))
|
||||
sexp_set_twos_complement(res);
|
||||
if (sexp_fixnump(y)) {
|
||||
if (sexp_fixnump(y) || sexp_bignum_sign(y) < 0) {
|
||||
sexp_negate_exact(res);
|
||||
}
|
||||
} else {
|
||||
|
@ -188,6 +188,10 @@ sexp sexp_bit_xor (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp y) {
|
|||
= sexp_bignum_data(res)[i] ^ sexp_bignum_data(tmp)[i];
|
||||
if (sexp_bignum_sign(res) < 0)
|
||||
sexp_set_twos_complement(res);
|
||||
if (!((sexp_bignum_sign(x) < 0) ^ (sexp_bignum_sign(y) < 0))) {
|
||||
sexp_set_twos_complement(res);
|
||||
sexp_negate_exact(res);
|
||||
}
|
||||
} else {
|
||||
res = sexp_type_exception(ctx, self, SEXP_FIXNUM, y);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
(test -461856550205267621490541042387407516495872
|
||||
(bitwise-xor -1930735170000000000001689392892000000000000
|
||||
1689392892000000000000193073517000000000000))
|
||||
(test 461856550205267621490541042387407516495872
|
||||
(bitwise-xor -1930735170000000000001689392892000000000000
|
||||
-1689392892000000000000193073517000000000000))
|
||||
(test 3769478 (bitwise-and 1694076839 -4290775858))
|
||||
(test 1680869008 (bitwise-and -193073517 1689392892))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue