From bbcb571ba51246162d6da67472e089b779b6aa62 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Tue, 21 May 2019 22:26:37 +0800 Subject: [PATCH] fix comparison of negative bignums (issue #541) --- bignum.c | 3 ++- lib/chibi/numeric-test.sld | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bignum.c b/bignum.c index 526fa536..f61a7b6a 100644 --- a/bignum.c +++ b/bignum.c @@ -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) { if (sexp_bignum_sign(a) != sexp_bignum_sign(b)) 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) { diff --git a/lib/chibi/numeric-test.sld b/lib/chibi/numeric-test.sld index 9d476ebc..c329be29 100644 --- a/lib/chibi/numeric-test.sld +++ b/lib/chibi/numeric-test.sld @@ -272,6 +272,11 @@ (+ 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))