diff --git a/bignum.c b/bignum.c index 097aced1..48a71b84 100644 --- a/bignum.c +++ b/bignum.c @@ -999,8 +999,8 @@ sexp sexp_complex_sub (sexp ctx, sexp a, sexp b) { sexp_gc_var2(res, tmp); sexp_gc_preserve2(ctx, res, tmp); tmp = sexp_complex_copy(ctx, b); - sexp_negate(sexp_complex_real(tmp)); - sexp_negate(sexp_complex_imag(tmp)); + sexp_negate_maybe_ratio(sexp_complex_real(tmp)); + sexp_negate_maybe_ratio(sexp_complex_imag(tmp)); res = sexp_complex_add(ctx, a, tmp); sexp_gc_release2(ctx); return res; @@ -1453,11 +1453,7 @@ sexp sexp_sub (sexp ctx, sexp a, sexp b) { sexp_negate_exact(sexp_ratio_numerator(tmp2)); r = sexp_ratio_add(ctx, a, tmp2); if (negatep) { - if (sexp_ratiop(r)) { - sexp_negate_exact(sexp_ratio_numerator(r)); - } else { - sexp_negate_exact(r); - } + sexp_negate_maybe_ratio(r); } break; #endif @@ -1489,10 +1485,10 @@ sexp sexp_sub (sexp ctx, sexp a, sexp b) { if (negatep) { if (sexp_complexp(r)) { r = sexp_complex_copy(ctx, r); - sexp_negate(sexp_complex_real(r)); - sexp_negate(sexp_complex_imag(r)); + sexp_negate_maybe_ratio(sexp_complex_real(r)); + sexp_negate_maybe_ratio(sexp_complex_imag(r)); } else { - sexp_negate(r); + sexp_negate_maybe_ratio(r); } } break; diff --git a/sexp.c b/sexp.c index c0b65b69..4ae00bcf 100644 --- a/sexp.c +++ b/sexp.c @@ -3632,9 +3632,9 @@ sexp sexp_read_raw (sexp ctx, sexp in, sexp *shares) { #if SEXP_USE_COMPLEX if (sexp_complexp(res)) { if (sexp_complex_real(res) == SEXP_ZERO) { - sexp_negate(sexp_complex_imag(res)); + sexp_negate_maybe_ratio(sexp_complex_imag(res)); } else { - sexp_negate(sexp_complex_real(res)); + sexp_negate_maybe_ratio(sexp_complex_real(res)); } } else #endif diff --git a/tests/r7rs-tests.scm b/tests/r7rs-tests.scm index 602fc5c4..24f6e94f 100644 --- a/tests/r7rs-tests.scm +++ b/tests/r7rs-tests.scm @@ -889,6 +889,8 @@ (test -1 (- 3 4)) (test -6 (- 3 4 5)) (test -3 (- 3)) +(test -3/2 (- 3/2)) +(test -3/2-i (- 3/2+i)) (test 3/20 (/ 3 4 5)) (test 1/3 (/ 3))