Zero angle polars are real. Fixes issue #329.

This commit is contained in:
Alex Shinn 2016-05-04 21:31:55 +09:00
parent 64b8e5f8a3
commit 2a05db5382
2 changed files with 9 additions and 0 deletions

2
eval.c
View file

@ -1778,6 +1778,8 @@ sexp sexp_inexact_to_exact (sexp ctx, sexp self, sexp_sint_t n, sexp z) {
res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO); res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
sexp_complex_real(res) = sexp_inexact_to_exact(ctx, self, 1, sexp_complex_real(z)); sexp_complex_real(res) = sexp_inexact_to_exact(ctx, self, 1, sexp_complex_real(z));
sexp_complex_imag(res) = sexp_inexact_to_exact(ctx, self, 1, sexp_complex_imag(z)); sexp_complex_imag(res) = sexp_inexact_to_exact(ctx, self, 1, sexp_complex_imag(z));
if (sexp_complex_imag(res) == SEXP_ZERO)
res = sexp_complex_real(res);
sexp_gc_release1(ctx); sexp_gc_release1(ctx);
} }
#endif #endif

7
sexp.c
View file

@ -2357,6 +2357,8 @@ sexp sexp_read_polar_tail (sexp ctx, sexp in, sexp magnitude) {
res = theta; res = theta;
} else if (sexp_complexp(theta) || !sexp_numberp(theta)) { } else if (sexp_complexp(theta) || !sexp_numberp(theta)) {
res = sexp_read_error(ctx, "invalid polar numeric syntax", theta, in); res = sexp_read_error(ctx, "invalid polar numeric syntax", theta, in);
} else if (theta == SEXP_ZERO) {
res = magnitude;
} else { } else {
res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO); res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
sexp_complex_real(res) = sexp_cos(ctx, NULL, 1, theta); sexp_complex_real(res) = sexp_cos(ctx, NULL, 1, theta);
@ -2828,6 +2830,11 @@ sexp sexp_read_raw (sexp ctx, sexp in, sexp *shares) {
&& (isnan(sexp_flonum_value(res)) || isinf(sexp_flonum_value(res)))) && (isnan(sexp_flonum_value(res)) || isinf(sexp_flonum_value(res))))
res = sexp_read_error(ctx, "can't convert non-finite flonum to exact", res, in); res = sexp_read_error(ctx, "can't convert non-finite flonum to exact", res, in);
else else
#endif
#if SEXP_USE_COMPLEX
if (sexp_complexp(res))
res = sexp_inexact_to_exact(ctx, NULL, 1, res);
else
#endif #endif
if (sexp_flonump(res)) if (sexp_flonump(res))
#if SEXP_USE_RATIOS #if SEXP_USE_RATIOS