mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
Raise type error if remainder called with infinity.
To prevent an infinite loop, raise a type error if the remainder procedure is called with +inf.0 or -inf.0 as either argument.
This commit is contained in:
parent
f0c9f0e705
commit
e5d9ccb69f
1 changed files with 6 additions and 2 deletions
8
bignum.c
8
bignum.c
|
@ -1667,8 +1667,11 @@ sexp sexp_remainder (sexp ctx, sexp a, sexp b) {
|
|||
#if SEXP_USE_RATIOS
|
||||
case SEXP_NUM_FLO_RAT:
|
||||
#endif
|
||||
if (sexp_flonum_value(a) != trunc(sexp_flonum_value(a))) {
|
||||
if (isinf(sexp_flonum_value(a)) ||
|
||||
sexp_flonum_value(a) != trunc(sexp_flonum_value(a))) {
|
||||
r = sexp_type_exception(ctx, NULL, SEXP_FIXNUM, a);
|
||||
} else if (bt == SEXP_NUM_FLO && isinf(sexp_flonum_value(b))) {
|
||||
r = sexp_type_exception(ctx, NULL, SEXP_FIXNUM, b);
|
||||
} else {
|
||||
tmp = sexp_bignum_normalize(sexp_double_to_bignum(ctx, sexp_flonum_value(a)));
|
||||
tmp = sexp_remainder(ctx, tmp, b);
|
||||
|
@ -1691,7 +1694,8 @@ sexp sexp_remainder (sexp ctx, sexp a, sexp b) {
|
|||
#if SEXP_USE_RATIOS
|
||||
case SEXP_NUM_RAT_FLO:
|
||||
#endif
|
||||
if (sexp_flonum_value(b) != trunc(sexp_flonum_value(b))) {
|
||||
if (isinf(sexp_flonum_value(b)) ||
|
||||
sexp_flonum_value(b) != trunc(sexp_flonum_value(b))) {
|
||||
r = sexp_type_exception(ctx, NULL, SEXP_FIXNUM, b);
|
||||
} else {
|
||||
tmp = sexp_bignum_normalize(sexp_double_to_bignum(ctx, sexp_flonum_value(b)));
|
||||
|
|
Loading…
Add table
Reference in a new issue