mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-04 19:56:36 +02:00
removing references to round when not compiling with math or flonums
This commit is contained in:
parent
902b38ab88
commit
2ac6e8fe33
3 changed files with 19 additions and 13 deletions
21
eval.c
21
eval.c
|
@ -1301,7 +1301,7 @@ sexp sexp_sqrt (sexp ctx, sexp self, sexp_sint_t n, sexp z) {
|
||||||
|
|
||||||
#endif /* SEXP_USE_MATH */
|
#endif /* SEXP_USE_MATH */
|
||||||
|
|
||||||
#if SEXP_USE_RATIOS
|
#if SEXP_USE_RATIOS || !SEXP_USE_FLONUMS
|
||||||
sexp sexp_generic_expt (sexp ctx, sexp x, sexp_sint_t e) {
|
sexp sexp_generic_expt (sexp ctx, sexp x, sexp_sint_t e) {
|
||||||
sexp_gc_var2(res, tmp);
|
sexp_gc_var2(res, tmp);
|
||||||
sexp_gc_preserve2(ctx, res, tmp);
|
sexp_gc_preserve2(ctx, res, tmp);
|
||||||
|
@ -1315,6 +1315,11 @@ sexp sexp_generic_expt (sexp ctx, sexp x, sexp_sint_t e) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sexp sexp_expt_op (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp e) {
|
sexp sexp_expt_op (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp e) {
|
||||||
|
#if !SEXP_USE_FLONUMS
|
||||||
|
sexp_assert_type(ctx, sexp_fixnump, SEXP_FIXNUM, x);
|
||||||
|
sexp_assert_type(ctx, sexp_fixnump, SEXP_FIXNUM, e);
|
||||||
|
return sexp_generic_expt(ctx, x, sexp_unbox_fixnum(e));
|
||||||
|
#else
|
||||||
long double f, x1, e1;
|
long double f, x1, e1;
|
||||||
sexp res;
|
sexp res;
|
||||||
#if SEXP_USE_COMPLEX
|
#if SEXP_USE_COMPLEX
|
||||||
|
@ -1337,10 +1342,8 @@ sexp sexp_expt_op (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp e) {
|
||||||
#endif
|
#endif
|
||||||
if (sexp_fixnump(x))
|
if (sexp_fixnump(x))
|
||||||
x1 = sexp_unbox_fixnum(x);
|
x1 = sexp_unbox_fixnum(x);
|
||||||
#if SEXP_USE_FLONUMS
|
|
||||||
else if (sexp_flonump(x))
|
else if (sexp_flonump(x))
|
||||||
x1 = sexp_flonum_value(x);
|
x1 = sexp_flonum_value(x);
|
||||||
#endif
|
|
||||||
#if SEXP_USE_RATIOS
|
#if SEXP_USE_RATIOS
|
||||||
else if (sexp_ratiop(x)) {
|
else if (sexp_ratiop(x)) {
|
||||||
if (sexp_fixnump(e)) {
|
if (sexp_fixnump(e)) {
|
||||||
|
@ -1354,10 +1357,8 @@ sexp sexp_expt_op (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp e) {
|
||||||
return sexp_type_exception(ctx, self, SEXP_FIXNUM, x);
|
return sexp_type_exception(ctx, self, SEXP_FIXNUM, x);
|
||||||
if (sexp_fixnump(e))
|
if (sexp_fixnump(e))
|
||||||
e1 = sexp_unbox_fixnum(e);
|
e1 = sexp_unbox_fixnum(e);
|
||||||
#if SEXP_USE_FLONUMS
|
|
||||||
else if (sexp_flonump(e))
|
else if (sexp_flonump(e))
|
||||||
e1 = sexp_flonum_value(e);
|
e1 = sexp_flonum_value(e);
|
||||||
#endif
|
|
||||||
#if SEXP_USE_RATIOS
|
#if SEXP_USE_RATIOS
|
||||||
else if (sexp_ratiop(e))
|
else if (sexp_ratiop(e))
|
||||||
e1 = sexp_ratio_to_double(e);
|
e1 = sexp_ratio_to_double(e);
|
||||||
|
@ -1366,26 +1367,20 @@ sexp sexp_expt_op (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp e) {
|
||||||
return sexp_type_exception(ctx, self, SEXP_FIXNUM, e);
|
return sexp_type_exception(ctx, self, SEXP_FIXNUM, e);
|
||||||
f = pow(x1, e1);
|
f = pow(x1, e1);
|
||||||
if ((f*1000.0 > SEXP_MAX_FIXNUM) || (f*1000.0 < SEXP_MIN_FIXNUM)
|
if ((f*1000.0 > SEXP_MAX_FIXNUM) || (f*1000.0 < SEXP_MIN_FIXNUM)
|
||||||
#if SEXP_USE_FLONUMS
|
|| (! sexp_fixnump(x)) || (! sexp_fixnump(e))) {
|
||||||
|| (! sexp_fixnump(x)) || (! sexp_fixnump(e))
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
#if SEXP_USE_BIGNUMS
|
#if SEXP_USE_BIGNUMS
|
||||||
if (sexp_fixnump(x) && sexp_fixnump(e))
|
if (sexp_fixnump(x) && sexp_fixnump(e))
|
||||||
res = sexp_bignum_expt(ctx, sexp_fixnum_to_bignum(ctx, x), e);
|
res = sexp_bignum_expt(ctx, sexp_fixnum_to_bignum(ctx, x), e);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
#if SEXP_USE_FLONUMS
|
|
||||||
res = sexp_make_flonum(ctx, f);
|
res = sexp_make_flonum(ctx, f);
|
||||||
#else
|
|
||||||
res = sexp_make_fixnum((sexp_sint_t)round(f));
|
|
||||||
#endif
|
|
||||||
} else
|
} else
|
||||||
res = sexp_make_fixnum((sexp_sint_t)round(f));
|
res = sexp_make_fixnum((sexp_sint_t)round(f));
|
||||||
#if SEXP_USE_BIGNUMS
|
#if SEXP_USE_BIGNUMS
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return res;
|
return res;
|
||||||
|
#endif /* !SEXP_USE_FLONUMS */
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SEXP_USE_RATIOS
|
#if SEXP_USE_RATIOS
|
||||||
|
|
|
@ -1098,6 +1098,13 @@ SEXP_API sexp_heap sexp_global_heap;
|
||||||
#define sexp_fp_mul(x,a,b) (sexp_make_flonum(x, sexp_flonum_value(a) * sexp_flonum_value(b)))
|
#define sexp_fp_mul(x,a,b) (sexp_make_flonum(x, sexp_flonum_value(a) * sexp_flonum_value(b)))
|
||||||
#define sexp_fp_div(x,a,b) (sexp_make_flonum(x, sexp_flonum_value(a) / sexp_flonum_value(b)))
|
#define sexp_fp_div(x,a,b) (sexp_make_flonum(x, sexp_flonum_value(a) / sexp_flonum_value(b)))
|
||||||
|
|
||||||
|
#if ! (SEXP_USE_FLONUMS || SEXP_USE_BIGNUMS)
|
||||||
|
#define sexp_add(ctx, a, b) sexp_fx_add(a, b)
|
||||||
|
#define sexp_sub(ctx, a, b) sexp_fx_sub(a, b)
|
||||||
|
#define sexp_mul(ctx, a, b) sexp_fx_mul(a, b)
|
||||||
|
#define sexp_div(ctx, a, b) sexp_fx_div(a, b)
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************** utilities *****************************/
|
/****************************** utilities *****************************/
|
||||||
|
|
||||||
enum sexp_context_globals {
|
enum sexp_context_globals {
|
||||||
|
|
4
vm.c
4
vm.c
|
@ -1667,6 +1667,7 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
||||||
top--;
|
top--;
|
||||||
break;
|
break;
|
||||||
case SEXP_OP_FIX2FLO:
|
case SEXP_OP_FIX2FLO:
|
||||||
|
#if SEXP_USE_FLONUMS
|
||||||
sexp_context_top(ctx) = top;
|
sexp_context_top(ctx) = top;
|
||||||
if (sexp_fixnump(_ARG1))
|
if (sexp_fixnump(_ARG1))
|
||||||
_ARG1 = sexp_fixnum_to_flonum(ctx, _ARG1);
|
_ARG1 = sexp_fixnum_to_flonum(ctx, _ARG1);
|
||||||
|
@ -1680,8 +1681,10 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
||||||
#endif
|
#endif
|
||||||
else if (! sexp_flonump(_ARG1))
|
else if (! sexp_flonump(_ARG1))
|
||||||
sexp_raise("exact->inexact: not a number", sexp_list1(ctx, _ARG1));
|
sexp_raise("exact->inexact: not a number", sexp_list1(ctx, _ARG1));
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case SEXP_OP_FLO2FIX:
|
case SEXP_OP_FLO2FIX:
|
||||||
|
#if SEXP_USE_FLONUMS
|
||||||
if (sexp_flonump(_ARG1)) {
|
if (sexp_flonump(_ARG1)) {
|
||||||
if (sexp_flonum_value(_ARG1) != trunc(sexp_flonum_value(_ARG1))) {
|
if (sexp_flonum_value(_ARG1) != trunc(sexp_flonum_value(_ARG1))) {
|
||||||
#if SEXP_USE_RATIOS
|
#if SEXP_USE_RATIOS
|
||||||
|
@ -1701,6 +1704,7 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
|
||||||
} else if (!sexp_exactp(_ARG1)) {
|
} else if (!sexp_exactp(_ARG1)) {
|
||||||
sexp_raise("inexact->exact: not a number", sexp_list1(ctx, _ARG1));
|
sexp_raise("inexact->exact: not a number", sexp_list1(ctx, _ARG1));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case SEXP_OP_CHAR2INT:
|
case SEXP_OP_CHAR2INT:
|
||||||
if (! sexp_charp(_ARG1))
|
if (! sexp_charp(_ARG1))
|
||||||
|
|
Loading…
Add table
Reference in a new issue