summaryrefslogtreecommitdiffhomepage
path: root/src/vm.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-08-18 22:12:28 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-10-12 16:21:48 +0900
commit2a92fb2516251fb0ddfa2d1026930a2c7465e528 (patch)
tree99fe336ea04b8aec484cb27baf13ae3c261d26b1 /src/vm.c
parent18e3d39ee23389d9a7955149c09b6de026804ca3 (diff)
downloadmruby-2a92fb2516251fb0ddfa2d1026930a2c7465e528.tar.gz
mruby-2a92fb2516251fb0ddfa2d1026930a2c7465e528.zip
Make division by zero cause `ZeroDivisionError`.
As described in ISO 15.2.30.
Diffstat (limited to 'src/vm.c')
-rw-r--r--src/vm.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/vm.c b/src/vm.c
index 979c67424..15a38c0e4 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2315,12 +2315,13 @@ RETRY_TRY_BLOCK:
{
mrb_int x = mrb_fixnum(regs[a]);
mrb_int y = mrb_fixnum(regs[a+1]);
- if (y == 0 || (x == MRB_INT_MIN && y == -1)) {
-#ifdef MRB_NO_FLOAT
- SET_INT_VALUE(regs[a], y ? x / y : 0);
-#else
- SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x / (mrb_float)y);
-#endif
+
+
+ if (y == 0) {
+ mrb_raise(mrb, E_ZERODIV_ERROR, "divided by 0");
+ }
+ else if(x == MRB_INT_MIN && y == -1) {
+ mrb_raise(mrb, E_RANGE_ERROR, "integer overflow in division");
}
else {
mrb_int div, mod;