harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 29f272f8b1cb52a0b310a82dabf450b6eddaafba
parent b164f4678a9cdbc52c96c5b8ddcffcfac8b27c2b
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 16 May 2022 13:53:30 +0200

Do not prevent FPEs in eval

This is necessary for math::NaN to work, which is defined as 0.0/0.0.

This reverts commit bbd01c3002170a72e7d82fdabd60dedd0cca9ae4.

Diffstat:
Msrc/eval.c | 26+++-----------------------
1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/src/eval.c b/src/eval.c @@ -181,23 +181,11 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou break; case BIN_DIV: if (type_is_float(lvalue.result)) { - double r = ftrunc(rvalue.result, frval); - if (r == 0) { - return EVAL_INVALID; - } - fval = ftrunc(lvalue.result, flval) / r; + fval = ftrunc(lvalue.result, flval) / ftrunc(rvalue.result, frval); } else if (type_is_signed(lvalue.result)) { - uintmax_t r = itrunc(rvalue.result, irval); - if (r == 0) { - return EVAL_INVALID; - } - ival = itrunc(lvalue.result, ilval) / r; + ival = itrunc(lvalue.result, ilval) / itrunc(rvalue.result, irval); } else { - uintmax_t r = itrunc(rvalue.result, urval); - if (r == 0) { - return EVAL_INVALID; - } - uval = itrunc(lvalue.result, ulval) / r; + uval = itrunc(lvalue.result, ulval) / itrunc(rvalue.result, urval); } break; case BIN_LSHIFT: @@ -217,16 +205,8 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou case BIN_MODULO: assert(!type_is_float(lvalue.result)); if (type_is_signed(lvalue.result)) { - uintmax_t r = itrunc(rvalue.result, irval); - if (r == 0) { - return EVAL_INVALID; - } ival = itrunc(lvalue.result, ilval) % itrunc(rvalue.result, irval); } else { - uintmax_t r = itrunc(rvalue.result, urval); - if (r == 0) { - return EVAL_INVALID; - } uval = itrunc(lvalue.result, ulval) % itrunc(rvalue.result, urval); } break;