fix comparison of negative bignums (issue #541)

This commit is contained in:
Alex Shinn 2019-05-21 22:26:37 +08:00
parent 104811942f
commit bbcb571ba5
2 changed files with 7 additions and 1 deletions

View file

@ -146,7 +146,8 @@ sexp_sint_t sexp_bignum_compare_abs (sexp a, sexp b) {
sexp_sint_t sexp_bignum_compare (sexp a, sexp b) { sexp_sint_t sexp_bignum_compare (sexp a, sexp b) {
if (sexp_bignum_sign(a) != sexp_bignum_sign(b)) if (sexp_bignum_sign(a) != sexp_bignum_sign(b))
return sexp_bignum_sign(a); return sexp_bignum_sign(a);
return sexp_bignum_compare_abs(a, b); sexp_sint_t cmp = sexp_bignum_compare_abs(a, b);
return sexp_bignum_sign(a) < 0 ? -cmp : cmp;
} }
sexp sexp_bignum_normalize (sexp a) { sexp sexp_bignum_normalize (sexp a) {

View file

@ -272,6 +272,11 @@
(+ 115792089237316195423570985008687907853099843482180094807725896704197245534208 (+ 115792089237316195423570985008687907853099843482180094807725896704197245534208
115792089237316195423570985008687907853099843482180094807725896704197245534208)) 115792089237316195423570985008687907853099843482180094807725896704197245534208))
(let ((smallest-s64 -9223372036854775808)
(small-bignum -100000000000000000000000000))
(test-assert (> smallest-s64 small-bignum))
(test-assert (< small-bignum smallest-s64)))
(test #f (< +nan.0 +nan.0)) (test #f (< +nan.0 +nan.0))
(test #f (<= +nan.0 +nan.0)) (test #f (<= +nan.0 +nan.0))
(test #f (= +nan.0 +nan.0)) (test #f (= +nan.0 +nan.0))