Fix math stuff

This commit is contained in:
2026-09-07 17:43:33 -07:00
parent 5503b2f317
commit 23fdd86ae0
5 changed files with 49 additions and 7 deletions
+5 -4
View File
@@ -94,7 +94,7 @@ static inline LispVal *type_for_operator(enum Operator op) {
LispVal *float_math_driver(enum Operator op, bool first, lisp_float_t acc,
LispVal *nums) {
assert(LISP_FLOAT_P(XCAR(nums)));
assert(!first || LISP_FLOAT_P(XCAR(nums)));
switch (op) {
case OPERATOR_AND:
case OPERATOR_IOR:
@@ -141,7 +141,7 @@ LispVal *float_math_driver(enum Operator op, bool first, lisp_float_t acc,
LispVal *gmp_math_driver(enum Operator op, bool first, fixnum_t fixnum_acc,
LispVal *nums) {
assert(LISP_GMP_P(XCAR(nums)));
assert(!first || LISP_GMP_P(XCAR(nums)));
LispGmp *acc = make_gmp(fixnum_acc);
if (first) {
mpz_set(acc->val, ((LispGmp *) XCAR(nums))->val);
@@ -233,7 +233,7 @@ LispVal *gmp_math_driver(enum Operator op, bool first, fixnum_t fixnum_acc,
}
}
if (mpz_cmp_si(acc->val, MOST_POSITIVE_FIXNUM) <= 0
|| mpz_cmp_si(acc->val, MOST_NEGATIVE_FIXNUM) >= 0) {
&& mpz_cmp_si(acc->val, MOST_NEGATIVE_FIXNUM) >= 0) {
return MAKE_FIXNUM(mpz_get_si(acc->val));
}
return acc;
@@ -285,7 +285,8 @@ LispVal *math_driver(enum Operator op, LispVal *nums) {
default:
abort();
}
if (did_overflow) {
if (did_overflow || out > MOST_POSITIVE_FIXNUM
|| out < MOST_NEGATIVE_FIXNUM) {
break;
}
acc = out;