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

ruby-changes:45767

From: naruse <ko1@a...>
Date: Sat, 11 Mar 2017 22:03:50 +0900 (JST)
Subject: [ruby-changes:45767] naruse:r57840 (ruby_2_4): merge revision(s) 57227: [Backport #13078]

naruse	2017-03-11 22:03:46 +0900 (Sat, 11 Mar 2017)

  New Revision: 57840

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

  Log:
    merge revision(s) 57227: [Backport #13078]
    
    numeric.c: reduce fdiv
    
    * numeric.c (rb_int_fdiv_double): reduce first for more precise
      result.  [ruby-core:78886] [Bug #13078]

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/internal.h
    branches/ruby_2_4/numeric.c
    branches/ruby_2_4/test/ruby/test_rational.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/internal.h
===================================================================
--- ruby_2_4/internal.h	(revision 57839)
+++ ruby_2_4/internal.h	(revision 57840)
@@ -1682,6 +1682,7 @@ VALUE rb_execarg_extract_options(VALUE e https://github.com/ruby/ruby/blob/trunk/ruby_2_4/internal.h#L1682
 void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
 
 /* rational.c (export) */
+VALUE rb_gcd(VALUE x, VALUE y);
 VALUE rb_gcd_normal(VALUE self, VALUE other);
 #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
 VALUE rb_gcd_gmp(VALUE x, VALUE y);
Index: ruby_2_4/numeric.c
===================================================================
--- ruby_2_4/numeric.c	(revision 57839)
+++ ruby_2_4/numeric.c	(revision 57840)
@@ -3614,6 +3614,13 @@ fix_fdiv_double(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/numeric.c#L3614
 double
 rb_int_fdiv_double(VALUE x, VALUE y)
 {
+    if (RB_INTEGER_TYPE_P(y) && !FIXNUM_ZERO_P(y)) {
+	VALUE gcd = rb_gcd(x, y);
+	if (!FIXNUM_ZERO_P(gcd)) {
+	    x = rb_int_idiv(x, gcd);
+	    y = rb_int_idiv(y, gcd);
+	}
+    }
     if (FIXNUM_P(x)) {
         return fix_fdiv_double(x, y);
     }
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 57839)
+++ ruby_2_4/version.h	(revision 57840)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.0"
 #define RUBY_RELEASE_DATE "2017-03-11"
-#define RUBY_PATCHLEVEL 8
+#define RUBY_PATCHLEVEL 9
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_4/test/ruby/test_rational.rb
===================================================================
--- ruby_2_4/test/ruby/test_rational.rb	(revision 57839)
+++ ruby_2_4/test/ruby/test_rational.rb	(revision 57840)
@@ -905,6 +905,13 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_rational.rb#L905
     assert_equal(5000000000.0, 10000000000.fdiv(2))
     assert_equal(0.5, 1.0.fdiv(2))
     assert_equal(0.25, Rational(1,2).fdiv(2))
+
+    a = 0xa42fcabf_c51ce400_00001000_00000000_00000000_00000000_00000000_00000000
+    b = 1<<1074
+    assert_equal(Rational(a, b).to_f, a.fdiv(b))
+    a = 3
+    b = 0x20_0000_0000_0001
+    assert_equal(Rational(a, b).to_f, a.fdiv(b))
   end
 
   def test_ruby19

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r57227


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

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