fix exact neg check for ratio in rounding (issue #539)

This commit is contained in:
Alex Shinn 2019-05-03 00:37:30 +08:00
parent 624b54c05c
commit 26ceb64434
2 changed files with 5 additions and 1 deletions

View file

@ -862,7 +862,7 @@ sexp sexp_ratio_round (sexp ctx, sexp a) {
r = sexp_mul(ctx, r, SEXP_TWO); r = sexp_mul(ctx, r, SEXP_TWO);
if (sexp_exact_negativep(r)) {sexp_negate(r);} if (sexp_exact_negativep(r)) {sexp_negate(r);}
if (sexp_unbox_fixnum(sexp_compare(ctx, r, sexp_ratio_denominator(a))) > 0) 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); sexp_gc_release2(ctx);
return q; return q;

View file

@ -932,6 +932,10 @@
(test 4 (round 7/2)) (test 4 (round 7/2))
(test 7 (round 7)) (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 1/3 (rationalize (exact .3) 1/10))
(test #i1/3 (rationalize .3 1/10)) (test #i1/3 (rationalize .3 1/10))