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_add),

test/bigdecimal/test_bigdecimal.rb:
  need to specify precision for converting Rational and Float.
  [ruby-core:48045] [Bug #7176]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2012-11-01 13:03:53 +00:00
parent a5fc96a5c1
commit 2e6b5ece95
3 changed files with 40 additions and 15 deletions

View file

@ -1,3 +1,10 @@
Thu Nov 1 21:52:20 2012 Kenta Murata <mrkn@mrkn.jp>
* ext/bigdecimal/bigdecimal.c (BigDecimal_add),
test/bigdecimal/test_bigdecimal.rb:
need to specify precision for converting Rational and Float.
[ruby-core:48045] [Bug #7176]
Thu Nov 1 21:42:20 2012 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_process.rb: Revert r37404. My ubuntu box has

View file

@ -821,21 +821,35 @@ BigDecimal_add(VALUE self, VALUE r)
ENTER(5);
Real *c, *a, *b;
size_t mx;
GUARD_OBJ(a,GetVpValue(self,1));
GUARD_OBJ(a, GetVpValue(self, 1));
if (TYPE(r) == T_FLOAT) {
b = GetVpValueWithPrec(r, DBL_DIG+1, 1);
}
else if (TYPE(r) == T_RATIONAL) {
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
}
else {
b = GetVpValue(r,0);
if(!b) return DoSomeOne(self,r,'+');
}
if (!b) return DoSomeOne(self,r,'+');
SAVE(b);
if(VpIsNaN(b)) return b->obj;
if(VpIsNaN(a)) return a->obj;
mx = GetAddSubPrec(a,b);
if (VpIsNaN(b)) return b->obj;
if (VpIsNaN(a)) return a->obj;
mx = GetAddSubPrec(a, b);
if (mx == (size_t)-1L) {
GUARD_OBJ(c,VpCreateRbObject(VpBaseFig() + 1, "0"));
VpAddSub(c, a, b, 1);
} else {
GUARD_OBJ(c,VpCreateRbObject(mx *(VpBaseFig() + 1), "0"));
}
else {
GUARD_OBJ(c, VpCreateRbObject(mx * (VpBaseFig() + 1), "0"));
if(!mx) {
VpSetInf(c,VpGetSign(a));
} else {
VpSetInf(c, VpGetSign(a));
}
else {
VpAddSub(c, a, b, 1);
}
}

View file

@ -587,6 +587,10 @@ class TestBigDecimal < Test::Unit::TestCase
a, b = BigDecimal("0.11111").coerce(1.quo(3))
assert_equal(BigDecimal("0." + "3"*a.precs[0]), a)
assert_nothing_raised(TypeError, '#7176') do
BigDecimal.new('1') + Rational(1)
end
end
def test_uplus