mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
assume polar tail for inexact complex following / (issue #333)
This commit is contained in:
parent
287753f2e3
commit
0f6e0f56e0
1 changed files with 15 additions and 0 deletions
15
sexp.c
15
sexp.c
|
@ -2799,6 +2799,9 @@ sexp sexp_read_number (sexp ctx, sexp in, int base, int exactp) {
|
|||
int c, digit, negativep = 0;
|
||||
#if SEXP_USE_PLACEHOLDER_DIGITS
|
||||
double whole = 0.0, scale = 0.1;
|
||||
#endif
|
||||
#if SEXP_USE_COMPLEX && SEXP_USE_MATH
|
||||
double rho, theta;
|
||||
#endif
|
||||
sexp_gc_var2(res, den);
|
||||
|
||||
|
@ -2902,6 +2905,18 @@ sexp sexp_read_number (sexp ctx, sexp in, int base, int exactp) {
|
|||
res = sexp_make_ratio(ctx, res, sexp_complex_imag(den));
|
||||
res = sexp_ratio_normalize(ctx, res, in);
|
||||
sexp_complex_imag(den) = res;
|
||||
#if SEXP_USE_MATH
|
||||
} else if (sexp_flonump(sexp_complex_real(den))) { /* assume polar */
|
||||
rho = sqrt(sexp_flonum_value(sexp_complex_real(den)) *
|
||||
sexp_flonum_value(sexp_complex_real(den)) +
|
||||
sexp_to_double(ctx, sexp_complex_imag(den)) +
|
||||
sexp_to_double(ctx, sexp_complex_imag(den)));
|
||||
theta = atan(sexp_to_double(ctx, sexp_complex_imag(den)) /
|
||||
sexp_flonum_value(sexp_complex_real(den)));
|
||||
rho = sexp_to_double(ctx, sexp_div(ctx, res, sexp_make_fixnum((sexp_sint_t)round(rho))));
|
||||
sexp_complex_real(den) = sexp_make_flonum(ctx, rho * cos(theta));
|
||||
sexp_complex_imag(den) = sexp_make_flonum(ctx, rho * sin(theta));
|
||||
#endif
|
||||
} else {
|
||||
res = sexp_make_ratio(ctx, res, sexp_complex_real(den));
|
||||
res = sexp_ratio_normalize(ctx, res, in);
|
||||
|
|
Loading…
Add table
Reference in a new issue