summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-27 12:51:28 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-27 12:51:28 +0000
commit77446d45a819cdaede88300f33e1b4c859a1163c (patch)
tree0f6336e835e38fdeee207f3d9168e5e54d47b3bd /numeric.c
parent8a3f0ce44aaa67675f8da477b11c17af767879ed (diff)
* numeric.c (num_div): should raise ZeroDivisionError.
* numeric.c (fix_divide): ditto. * test/ruby/test_numeric.rb (TestNumeric::test_divmod): avoid ZeroDivisionError in tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index ea931b2..36bf6b6 100644
--- a/numeric.c
+++ b/numeric.c
@@ -288,6 +288,7 @@ static VALUE num_floor(VALUE num);
static VALUE
num_div(VALUE x, VALUE y)
{
+ if (rb_equal(INT2FIX(0), y)) rb_num_zerodiv();
return num_floor(rb_funcall(x, '/', 1, y));
}
@@ -2261,11 +2262,15 @@ fix_divide(VALUE x, VALUE y, ID op)
return rb_big_div(x, y);
case T_FLOAT:
{
- double div = (double)FIX2LONG(x) / RFLOAT_VALUE(y);
+ double div;
+
if (op == '/') {
+ div = (double)FIX2LONG(x) / RFLOAT_VALUE(y);
return DOUBLE2NUM(div);
}
else {
+ if (RFLOAT_VALUE(y) == 0) rb_num_zerodiv();
+ div = (double)FIX2LONG(x) / RFLOAT_VALUE(y);
return rb_dbl2big(floor(div));
}
}