summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-25 12:29:00 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-25 12:29:00 +0000
commit448c66c5162259ba734ea16b9c300d762cc63914 (patch)
tree1c6984c76f33e819208e4202a7a067597da52936
parentb58230bcbdf49cbc47f9d9f225a98c242d990b91 (diff)
* ext/bigdecimal/bigdecimal.c (BigMath_s_exp): Fix for the cases when
the argument x is not a BigDecimal. This change is based on the patch made by Garth Snyder. [Fix GH-332] https://github.com/ruby/ruby/pull/332 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--ext/bigdecimal/bigdecimal.c2
-rw-r--r--test/bigdecimal/test_bigdecimal.rb34
3 files changed, 37 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a1c3c6153..5c3ed8b5c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Jun 25 21:26:00 2013 Kenta Murata <mrkn@mrkn.jp>
+
+ * ext/bigdecimal/bigdecimal.c (BigMath_s_exp): Fix for the cases when
+ the argument x is not a BigDecimal.
+ This change is based on the patch made by Garth Snyder.
+ [Fix GH-332] https://github.com/ruby/ruby/pull/332
+
Tue Jun 25 20:36:31 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (big2ulong): "check" argument removed.
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index ba8777635f..87587f81a0 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -2725,7 +2725,7 @@ BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec)
else if (vx == NULL) {
cannot_be_coerced_into_BigDecimal(rb_eArgError, x);
}
- RB_GC_GUARD(vx->obj);
+ x = RB_GC_GUARD(vx->obj);
n = prec + rmpd_double_figures();
negative = VpGetSign(vx) < 0;
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 07c79a8874..5cbafdafd4 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -1276,11 +1276,35 @@ class TestBigDecimal < Test::Unit::TestCase
end
def test_BigMath_exp
- n = 20
- assert_in_epsilon(Math.exp(n), BigMath.exp(BigDecimal("20"), n))
- assert_in_epsilon(Math.exp(40), BigMath.exp(BigDecimal("40"), n))
- assert_in_epsilon(Math.exp(-n), BigMath.exp(BigDecimal("-20"), n))
- assert_in_epsilon(Math.exp(-40), BigMath.exp(BigDecimal("-40"), n))
+ prec = 20
+ assert_in_epsilon(Math.exp(20), BigMath.exp(BigDecimal("20"), prec))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(BigDecimal("40"), prec))
+ assert_in_epsilon(Math.exp(-20), BigMath.exp(BigDecimal("-20"), prec))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(BigDecimal("-40"), prec))
+ end
+
+ def test_BigMath_exp_with_float
+ prec = 20
+ assert_in_epsilon(Math.exp(20), BigMath.exp(20.0, prec))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(40.0, prec))
+ assert_in_epsilon(Math.exp(-20), BigMath.exp(-20.0, prec))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(-40.0, prec))
+ end
+
+ def test_BigMath_exp_with_fixnum
+ prec = 20
+ assert_in_epsilon(Math.exp(20), BigMath.exp(20, prec))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(40, prec))
+ assert_in_epsilon(Math.exp(-20), BigMath.exp(-20, prec))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(-40, prec))
+ end
+
+ def test_BigMath_exp_with_rational
+ prec = 20
+ assert_in_epsilon(Math.exp(20), BigMath.exp(Rational(40,2), prec))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(Rational(80,2), prec))
+ assert_in_epsilon(Math.exp(-20), BigMath.exp(Rational(-40,2), prec))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(Rational(-80,2), prec))
end
def test_BigMath_exp_under_gc_stress