* 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
This commit is contained in:
mrkn 2013-06-25 12:29:00 +00:00
Родитель b58230bcbd
Коммит 448c66c516
3 изменённых файлов: 37 добавлений и 6 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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;

Просмотреть файл

@ -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