From 4d3f3af83689790f21b344abbfbe6bbdd483813e Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 27 Nov 2008 17:20:08 +0000 Subject: * ext/bigdecimal/bigdecimal.c (BigDecimal_DoDivmod): bigdecimal division (including modulo) should raise ZeroDivisionError as integer division. [incompatible] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'ext') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 62ff80a860..b7f5235111 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -1012,7 +1012,9 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod) if(VpIsNaN(a) || VpIsNaN(b)) goto NaN; if(VpIsInf(a) || VpIsInf(b)) goto NaN; - if(VpIsZero(b)) goto NaN; + if(VpIsZero(b)) { + rb_raise(rb_eZeroDivError, "divided by 0"); + } if(VpIsZero(a)) { GUARD_OBJ(c,VpCreateRbObject(1, "0")); GUARD_OBJ(d,VpCreateRbObject(1, "0")); @@ -1169,9 +1171,6 @@ BigDecimal_div2(int argc, VALUE *argv, VALUE self) Real *mod; obj = BigDecimal_DoDivmod(self,b,&div,&mod); if(obj!=(VALUE)0) return obj; - if(VpIsNaN(div) && rb_equal(b, INT2FIX(0))) { - rb_raise(rb_eZeroDivError, "divided by 0"); - } return BigDecimal_to_i(ToValue(div)); } else { /* div in BigDecimal sense */ U_LONG ix = (U_LONG)GetPositiveInt(n); -- cgit v1.2.3