From 26ceb6443444588806104c18edd3e1f3b19ef3ef Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Fri, 3 May 2019 00:37:30 +0800 Subject: [PATCH] fix exact neg check for ratio in rounding (issue #539) --- bignum.c | 2 +- tests/r7rs-tests.scm | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bignum.c b/bignum.c index 37b2de8e..526fa536 100644 --- a/bignum.c +++ b/bignum.c @@ -862,7 +862,7 @@ sexp sexp_ratio_round (sexp ctx, sexp a) { r = sexp_mul(ctx, r, SEXP_TWO); if (sexp_exact_negativep(r)) {sexp_negate(r);} if (sexp_unbox_fixnum(sexp_compare(ctx, r, sexp_ratio_denominator(a))) > 0) - q = sexp_add(ctx, q, (sexp_exact_positivep(q) ? SEXP_ONE : SEXP_NEG_ONE)); + q = sexp_add(ctx, q, (sexp_exact_negativep(sexp_ratio_numerator(a)) ? SEXP_NEG_ONE : SEXP_ONE)); } sexp_gc_release2(ctx); return q; diff --git a/tests/r7rs-tests.scm b/tests/r7rs-tests.scm index 174d9ba8..998abcc4 100644 --- a/tests/r7rs-tests.scm +++ b/tests/r7rs-tests.scm @@ -932,6 +932,10 @@ (test 4 (round 7/2)) (test 7 (round 7)) +(test 1 (round 7/10)) +(test -4 (round -7/2)) +(test -7 (round -7)) +(test -1 (round -7/10)) (test 1/3 (rationalize (exact .3) 1/10)) (test #i1/3 (rationalize .3 1/10))