mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-16 09:27:33 +02:00
catching more bitwise-xor cases
This commit is contained in:
parent
cb7eaa7fe6
commit
9cf8a3ddf3
2 changed files with 11 additions and 7 deletions
|
@ -164,17 +164,17 @@ sexp sexp_bit_xor (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp y) {
|
|||
#if SEXP_USE_BIGNUMS
|
||||
} else if (sexp_bignump(x)) {
|
||||
sexp_gc_preserve2(ctx, res, tmp);
|
||||
if (sexp_fixnump(y)) {
|
||||
if (sexp_fixnump(y) && sexp_unbox_fixnum(y) >= 0) {
|
||||
res = sexp_copy_bignum(ctx, NULL, x, 0);
|
||||
if (sexp_bignum_sign(res) < 0)
|
||||
sexp_set_twos_complement(res);
|
||||
sexp_bignum_data(res)[0] ^= sexp_unbox_fixnum(y);
|
||||
if (sexp_bignum_sign(res) < 0)
|
||||
sexp_set_twos_complement(res);
|
||||
} else if (sexp_bignump(y)) {
|
||||
if (sexp_bignum_length(x) >= sexp_bignum_length(y)) {
|
||||
} else if (sexp_bignump(y) || sexp_fixnump(y)) {
|
||||
if (sexp_fixnump(y) || sexp_bignum_length(x) >= sexp_bignum_length(y)) {
|
||||
res = sexp_copy_bignum(ctx, NULL, x, 0);
|
||||
tmp = sexp_twos_complement(ctx, y);
|
||||
tmp = sexp_fixnump(y) ? sexp_fixnum_to_twos_complement(ctx, y, sexp_bignum_length(x)) : sexp_twos_complement(ctx, y);
|
||||
len = sexp_bignum_length(tmp);
|
||||
} else {
|
||||
res = sexp_copy_bignum(ctx, NULL, y, 0);
|
||||
|
@ -186,10 +186,9 @@ sexp sexp_bit_xor (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp y) {
|
|||
for (i=0; i<len; i++)
|
||||
sexp_bignum_data(res)[i]
|
||||
= 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))) {
|
||||
if ((sexp_bignum_sign(x) < 0) ^ (sexp_fixnump(y) || sexp_bignum_sign(y) < 0))
|
||||
sexp_set_twos_complement(res);
|
||||
if (sexp_fixnump(y) || sexp_bignum_sign(y) < 0) {
|
||||
sexp_negate_exact(res);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
1689392892000000000000193073517000000000000))
|
||||
(test -2604237975 (bitwise-xor 1694076839 -4290775858))
|
||||
(test -1865418641 (bitwise-xor -193073517 1689392892))
|
||||
(test -1689392892000142479725
|
||||
(bitwise-xor -193073517 1689392892000000000000))
|
||||
(test -1510500507664429879296
|
||||
(bitwise-xor -193073517000000000000 1689392892000000000000))
|
||||
(test -1510500507664429879296
|
||||
|
@ -35,6 +37,9 @@
|
|||
(test -461856550205267621490541042387407516495872
|
||||
(bitwise-xor -1930735170000000000001689392892000000000000
|
||||
1689392892000000000000193073517000000000000))
|
||||
(test -461856550205267621490541042387407516495872
|
||||
(bitwise-xor 1689392892000000000000193073517000000000000
|
||||
-1930735170000000000001689392892000000000000))
|
||||
(test 461856550205267621490541042387407516495872
|
||||
(bitwise-xor -1930735170000000000001689392892000000000000
|
||||
-1689392892000000000000193073517000000000000))
|
||||
|
|
Loading…
Add table
Reference in a new issue