removing references to round when not compiling with math or flonums

This commit is contained in:
Alex Shinn 2012-01-24 21:52:11 +09:00
parent 902b38ab88
commit 2ac6e8fe33
3 changed files with 19 additions and 13 deletions

21
eval.c
View file

@ -1301,7 +1301,7 @@ sexp sexp_sqrt (sexp ctx, sexp self, sexp_sint_t n, sexp z) {
#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_gc_var2(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
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;
sexp res;
#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
if (sexp_fixnump(x))
x1 = sexp_unbox_fixnum(x);
#if SEXP_USE_FLONUMS
else if (sexp_flonump(x))
x1 = sexp_flonum_value(x);
#endif
#if SEXP_USE_RATIOS
else if (sexp_ratiop(x)) {
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);
if (sexp_fixnump(e))
e1 = sexp_unbox_fixnum(e);
#if SEXP_USE_FLONUMS
else if (sexp_flonump(e))
e1 = sexp_flonum_value(e);
#endif
#if SEXP_USE_RATIOS
else if (sexp_ratiop(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);
f = pow(x1, e1);
if ((f*1000.0 > SEXP_MAX_FIXNUM) || (f*1000.0 < SEXP_MIN_FIXNUM)
#if SEXP_USE_FLONUMS
|| (! sexp_fixnump(x)) || (! sexp_fixnump(e))
#endif
) {
|| (! sexp_fixnump(x)) || (! sexp_fixnump(e))) {
#if SEXP_USE_BIGNUMS
if (sexp_fixnump(x) && sexp_fixnump(e))
res = sexp_bignum_expt(ctx, sexp_fixnum_to_bignum(ctx, x), e);
else
#endif
#if SEXP_USE_FLONUMS
res = sexp_make_flonum(ctx, f);
#else
res = sexp_make_fixnum((sexp_sint_t)round(f));
#endif
} else
res = sexp_make_fixnum((sexp_sint_t)round(f));
#if SEXP_USE_BIGNUMS
}
#endif
return res;
#endif /* !SEXP_USE_FLONUMS */
}
#if SEXP_USE_RATIOS

View file

@ -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_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 *****************************/
enum sexp_context_globals {

4
vm.c
View file

@ -1667,6 +1667,7 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
top--;
break;
case SEXP_OP_FIX2FLO:
#if SEXP_USE_FLONUMS
sexp_context_top(ctx) = top;
if (sexp_fixnump(_ARG1))
_ARG1 = sexp_fixnum_to_flonum(ctx, _ARG1);
@ -1680,8 +1681,10 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
#endif
else if (! sexp_flonump(_ARG1))
sexp_raise("exact->inexact: not a number", sexp_list1(ctx, _ARG1));
#endif
break;
case SEXP_OP_FLO2FIX:
#if SEXP_USE_FLONUMS
if (sexp_flonump(_ARG1)) {
if (sexp_flonum_value(_ARG1) != trunc(sexp_flonum_value(_ARG1))) {
#if SEXP_USE_RATIOS
@ -1701,6 +1704,7 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
} else if (!sexp_exactp(_ARG1)) {
sexp_raise("inexact->exact: not a number", sexp_list1(ctx, _ARG1));
}
#endif
break;
case SEXP_OP_CHAR2INT:
if (! sexp_charp(_ARG1))