diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-25 12:29:00 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-25 12:29:00 +0000 |
commit | 448c66c5162259ba734ea16b9c300d762cc63914 (patch) | |
tree | 1c6984c76f33e819208e4202a7a067597da52936 /test/bigdecimal | |
parent | b58230bcbdf49cbc47f9d9f225a98c242d990b91 (diff) | |
download | ruby-448c66c5162259ba734ea16b9c300d762cc63914.tar.gz |
* 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
Diffstat (limited to 'test/bigdecimal')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 34 |
1 files changed, 29 insertions, 5 deletions
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 |