[前][次][番号順一覧][スレッド一覧]

ruby-changes:29571

From: mrkn <ko1@a...>
Date: Tue, 25 Jun 2013 21:29:13 +0900 (JST)
Subject: [ruby-changes:29571] mrkn:r41623 (trunk): * ext/bigdecimal/bigdecimal.c (BigMath_s_exp): Fix for the cases when

mrkn	2013-06-25 21:29:00 +0900 (Tue, 25 Jun 2013)

  New Revision: 41623

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41623

  Log:
    * 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

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/test/bigdecimal/test_bigdecimal.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41622)
+++ ChangeLog	(revision 41623)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jun 25 21:26:00 2013  Kenta Murata  <mrkn@m...>
+
+	* 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@f...>
 
 	* bignum.c (big2ulong): "check" argument removed.
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 41622)
+++ ext/bigdecimal/bigdecimal.c	(revision 41623)
@@ -2725,7 +2725,7 @@ BigMath_s_exp(VALUE klass, VALUE x, VALU https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2725
     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;
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 41622)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 41623)
@@ -1276,11 +1276,35 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1276
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]