mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 06:39:17 +02:00
log should promote to complex logic for negative inputs.
Fixes issue #166.
This commit is contained in:
parent
3c45fb564a
commit
bd3eec54d7
1 changed files with 28 additions and 1 deletions
29
eval.c
29
eval.c
|
@ -1308,7 +1308,6 @@ sexp sexp_register_optimization (sexp ctx, sexp self, sexp_sint_t n, sexp f, sex
|
||||||
}
|
}
|
||||||
|
|
||||||
define_math_op(sexp_exp, exp, sexp_complex_exp)
|
define_math_op(sexp_exp, exp, sexp_complex_exp)
|
||||||
define_math_op(sexp_log, log, sexp_complex_log)
|
|
||||||
define_math_op(sexp_sin, sin, sexp_complex_sin)
|
define_math_op(sexp_sin, sin, sexp_complex_sin)
|
||||||
define_math_op(sexp_cos, cos, sexp_complex_cos)
|
define_math_op(sexp_cos, cos, sexp_complex_cos)
|
||||||
define_math_op(sexp_tan, tan, sexp_complex_tan)
|
define_math_op(sexp_tan, tan, sexp_complex_tan)
|
||||||
|
@ -1345,6 +1344,34 @@ define_math_rounder(sexp_trunc, trunc, sexp_ratio_trunc)
|
||||||
define_math_rounder(sexp_floor, floor, sexp_ratio_floor)
|
define_math_rounder(sexp_floor, floor, sexp_ratio_floor)
|
||||||
define_math_rounder(sexp_ceiling, ceil, sexp_ratio_ceiling)
|
define_math_rounder(sexp_ceiling, ceil, sexp_ratio_ceiling)
|
||||||
|
|
||||||
|
sexp sexp_log (sexp ctx, sexp self, sexp_sint_t n, sexp z) {
|
||||||
|
double d;
|
||||||
|
#if SEXP_USE_COMPLEX
|
||||||
|
sexp_gc_var1(tmp);
|
||||||
|
if (sexp_complexp(z))
|
||||||
|
return sexp_complex_log(ctx, z);
|
||||||
|
#endif
|
||||||
|
if (sexp_flonump(z))
|
||||||
|
d = sexp_flonum_value(z);
|
||||||
|
else if (sexp_fixnump(z))
|
||||||
|
d = (double)sexp_unbox_fixnum(z);
|
||||||
|
maybe_convert_ratio(z)
|
||||||
|
maybe_convert_bignum(z)
|
||||||
|
else
|
||||||
|
return sexp_type_exception(ctx, self, SEXP_NUMBER, z);
|
||||||
|
#if SEXP_USE_COMPLEX
|
||||||
|
if (d < 0) {
|
||||||
|
sexp_gc_preserve1(ctx, tmp);
|
||||||
|
tmp = sexp_make_flonum(ctx, d);
|
||||||
|
tmp = sexp_make_complex(ctx, tmp, SEXP_ZERO);
|
||||||
|
tmp = sexp_complex_log(ctx, tmp);
|
||||||
|
sexp_gc_release1(ctx);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return sexp_make_flonum(ctx, log(d));
|
||||||
|
}
|
||||||
|
|
||||||
sexp sexp_sqrt (sexp ctx, sexp self, sexp_sint_t n, sexp z) {
|
sexp sexp_sqrt (sexp ctx, sexp self, sexp_sint_t n, sexp z) {
|
||||||
#if SEXP_USE_COMPLEX
|
#if SEXP_USE_COMPLEX
|
||||||
int negativep = 0;
|
int negativep = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue