inexact->exact can convert non-integers when exact ratios are supported

This commit is contained in:
Alex Shinn 2011-11-27 21:50:49 +09:00
parent a4bd018480
commit 7b7c2aed8e
2 changed files with 5 additions and 0 deletions

View file

@ -39,6 +39,7 @@ sexp sexp_div (sexp ctx, sexp a, sexp b);
sexp sexp_quotient (sexp ctx, sexp a, sexp b); sexp sexp_quotient (sexp ctx, sexp a, sexp b);
sexp sexp_remainder (sexp ctx, sexp a, sexp b); sexp sexp_remainder (sexp ctx, sexp a, sexp b);
#if SEXP_USE_RATIOS #if SEXP_USE_RATIOS
sexp sexp_double_to_ratio (sexp ctx, double f);
double sexp_ratio_to_double (sexp rat); double sexp_ratio_to_double (sexp rat);
sexp sexp_make_ratio (sexp ctx, sexp num, sexp den); sexp sexp_make_ratio (sexp ctx, sexp num, sexp den);
sexp sexp_ratio_normalize (sexp ctx, sexp rat, sexp in); sexp sexp_ratio_normalize (sexp ctx, sexp rat, sexp in);

4
vm.c
View file

@ -1670,7 +1670,11 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
case SEXP_OP_FLO2FIX: case SEXP_OP_FLO2FIX:
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
_ARG1 = sexp_double_to_ratio(ctx, sexp_flonum_value(_ARG1));
#else
sexp_raise("inexact->exact: not an integer", sexp_list1(ctx, _ARG1)); sexp_raise("inexact->exact: not an integer", sexp_list1(ctx, _ARG1));
#endif
#if SEXP_USE_BIGNUMS #if SEXP_USE_BIGNUMS
} else if ((sexp_flonum_value(_ARG1) > SEXP_MAX_FIXNUM) } else if ((sexp_flonum_value(_ARG1) > SEXP_MAX_FIXNUM)
|| sexp_flonum_value(_ARG1) < SEXP_MIN_FIXNUM) { || sexp_flonum_value(_ARG1) < SEXP_MIN_FIXNUM) {