summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--ext/bigdecimal/bigdecimal.c44
-rw-r--r--test/bigdecimal/test_bigdecimal.rb4
-rw-r--r--version.h2
4 files changed, 41 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 7867194e98..962434639a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Nov 8 14:09:18 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 8 14:05:31 2012 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (has_redirection): should use shell (cmd.exe) when
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index fa6a696242..b344153bfd 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -808,23 +808,37 @@ BigDecimal_add(VALUE self, VALUE r)
ENTER(5);
Real *c, *a, *b;
size_t mx;
- GUARD_OBJ(a,GetVpValue(self,1));
- b = GetVpValue(r,0);
- if(!b) return DoSomeOne(self,r,'+');
+
+ 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,'+');
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"));
- if(!mx) {
- VpSetInf(c,VpGetSign(a));
- } else {
- VpAddSub(c, a, b, 1);
- }
+ GUARD_OBJ(c,VpCreateRbObject(VpBaseFig() + 1, "0"));
+ VpAddSub(c, a, b, 1);
+ }
+ else {
+ GUARD_OBJ(c, VpCreateRbObject(mx * (VpBaseFig() + 1), "0"));
+ if(!mx) {
+ VpSetInf(c, VpGetSign(a));
+ }
+ else {
+ VpAddSub(c, a, b, 1);
+ }
}
return ToValue(c);
}
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index e230624028..ed3639f058 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -558,6 +558,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
diff --git a/version.h b/version.h
index d2f6b39a30..09b049d21c 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 306
+#define RUBY_PATCHLEVEL 307
#define RUBY_RELEASE_DATE "2012-11-08"
#define RUBY_RELEASE_YEAR 2012