1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2008-11-27 17:20:08 +00:00
parent 6fd76fdb14
commit 4d3f3af836
3 changed files with 10 additions and 7 deletions

View file

@ -1,3 +1,9 @@
Fri Nov 28 02:18:47 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/bigdecimal/bigdecimal.c (BigDecimal_DoDivmod): bigdecimal
division (including modulo) should raise ZeroDivisionError as
integer division. [incompatible]
Fri Nov 28 00:12:00 2008 Yukihiro Matsumoto <matz@ruby-lang.org> Fri Nov 28 00:12:00 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (flodivmod): floating point division should raise * numeric.c (flodivmod): floating point division should raise

View file

@ -1012,7 +1012,9 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
if(VpIsNaN(a) || VpIsNaN(b)) goto NaN; if(VpIsNaN(a) || VpIsNaN(b)) goto NaN;
if(VpIsInf(a) || VpIsInf(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)) { if(VpIsZero(a)) {
GUARD_OBJ(c,VpCreateRbObject(1, "0")); GUARD_OBJ(c,VpCreateRbObject(1, "0"));
GUARD_OBJ(d,VpCreateRbObject(1, "0")); GUARD_OBJ(d,VpCreateRbObject(1, "0"));
@ -1169,9 +1171,6 @@ BigDecimal_div2(int argc, VALUE *argv, VALUE self)
Real *mod; Real *mod;
obj = BigDecimal_DoDivmod(self,b,&div,&mod); obj = BigDecimal_DoDivmod(self,b,&div,&mod);
if(obj!=(VALUE)0) return obj; 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)); return BigDecimal_to_i(ToValue(div));
} else { /* div in BigDecimal sense */ } else { /* div in BigDecimal sense */
U_LONG ix = (U_LONG)GetPositiveInt(n); U_LONG ix = (U_LONG)GetPositiveInt(n);

View file

@ -419,9 +419,7 @@ class TestBigDecimal < Test::Unit::TestCase
assert_equal([0, 0], BigDecimal.new("0").divmod(2)) assert_equal([0, 0], BigDecimal.new("0").divmod(2))
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false) BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
a, b = BigDecimal.new("0").divmod(0) assert_raise(ZeroDivisionError){BigDecimal.new("0").divmod(0)}
assert_equal(true, a.nan?)
assert_equal(true, b.nan?)
end end
def test_add_bigdecimal def test_add_bigdecimal