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

ruby-changes:43049

From: nobu <ko1@a...>
Date: Mon, 23 May 2016 12:30:35 +0900 (JST)
Subject: [ruby-changes:43049] nobu:r55123 (trunk): bigdecimal.c: fix FloatDomainError

nobu	2016-05-23 12:30:30 +0900 (Mon, 23 May 2016)

  New Revision: 55123

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55123

  Log:
    bigdecimal.c: fix FloatDomainError
    
    * ext/bigdecimal/bigdecimal.c (GetVpValueWithPrec): consider
      non-finite float values not to raise FloatDomainError.
      [ruby-core:75682] [Bug #12414]

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/test/bigdecimal/test_bigdecimal.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55122)
+++ ChangeLog	(revision 55123)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon May 23 12:30:29 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/bigdecimal/bigdecimal.c (GetVpValueWithPrec): consider
+	  non-finite float values not to raise FloatDomainError.
+	  [ruby-core:75682] [Bug #12414]
+
 Mon May 23 12:21:18 2016  NARUSE, Yui  <naruse@r...>
 
 	* array.c (rb_ary_fill): suppress warnings: 'item' may be used
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 55122)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 55123)
@@ -459,6 +459,18 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L459
     assert_equal(false, BigDecimal.new("NaN") > n1)
   end
 
+  def test_cmp_float_nan
+    assert_equal(nil, BigDecimal.new("1") <=> Float::NAN)
+  end
+
+  def test_cmp_float_pos_inf
+    assert_equal(-1, BigDecimal.new("1") <=> Float::INFINITY)
+  end
+
+  def test_cmp_float_neg_inf
+    assert_equal(+1, BigDecimal.new("1") <=> -Float::INFINITY)
+  end
+
   def test_cmp_failing_coercion
     n1 = BigDecimal.new("1")
     assert_equal(nil, n1 <=> nil)
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 55122)
+++ ext/bigdecimal/bigdecimal.c	(revision 55123)
@@ -239,6 +239,12 @@ again: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L239
 	if (prec < 0) goto unable_to_coerce_without_prec;
 	if (prec > DBL_DIG+1) goto SomeOneMayDoIt;
 	d = RFLOAT_VALUE(v);
+	if (!isfinite(d)) {
+	    pv = VpCreateRbObject(prec, NULL);
+	    pv->sign = isnan(d) ? VP_SIGN_NaN :
+		d > 0 ? VP_SIGN_POSITIVE_INFINITE : VP_SIGN_NEGATIVE_FINITE;
+	    return pv;
+	}
 	if (d != 0.0) {
 	    v = rb_funcall(v, id_to_r, 0);
 	    goto again;

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

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