diff options
author | itchyny <itchyny@cybozu.co.jp> | 2023-07-31 12:48:14 +0900 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2023-07-31 15:39:13 -0500 |
commit | 0f80921268edcc3d502e6d84612ba71fed6b0947 (patch) | |
tree | 40da8d84c1235bd94b5018a3fd015a60a7cda44f /src/compile.h | |
parent | 6716e23ae6d534db0d3f2af2d1610f17444fb5a9 (diff) |
Fix constant folding of division and reminder with zero divisor
Previously constant folding of zero division (e.x. 1/0) produces a
compile error. This was incorrectly implemented by checking if the
division result is infinite, so produces wrong results compared to the
query where no constant folding is processed (e.x. 1e308/0.1). This
patch delays the operation when the divisor is zero. This makes the
results more consistent, but changes the exit code on zero division from
3 to 5. Also 0/0 now produces the zero division error, not NaN.
This patch also fixes the modulo operation. Previously constant folding
logic does not take care of the % operator, but now it folds if the both
dividend and divisor are safe numbers to cast to the integer type, and
the divisor is not zero. This patch also fixes some code that relies on
undefined cast behaviors in C. The modulo operation produces NaN if
either the dividend or divisor is NaN.
Diffstat (limited to 'src/compile.h')
-rw-r--r-- | src/compile.h | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/src/compile.h b/src/compile.h index f690adc2..03cb54f5 100644 --- a/src/compile.h +++ b/src/compile.h @@ -22,7 +22,6 @@ block gen_op_simple(opcode op); block gen_const(jv constant); block gen_const_global(jv constant, const char *name); int block_is_const(block b); -int block_is_const_inf(block b); jv_kind block_const_kind(block b); jv block_const(block b); block gen_op_target(opcode op, block target); |