mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
properly handling negation of complex numbers with ratio parts (fixes issue #815)
This commit is contained in:
parent
82d61b3d8e
commit
fae48a3790
3 changed files with 10 additions and 12 deletions
16
bignum.c
16
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;
|
||||
|
|
4
sexp.c
4
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
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue