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

ruby-changes:45770

From: naruse <ko1@a...>
Date: Sat, 11 Mar 2017 22:35:27 +0900 (JST)
Subject: [ruby-changes:45770] naruse:r57843 (ruby_2_4): merge revision(s) 57232: [Backport #13084]

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

  New Revision: 57843

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

  Log:
    merge revision(s) 57232: [Backport #13084]
    
    rational.c: fix for mathn
    
    * rational.c (read_num, read_rat_nos): dispatch by the type of numerator, for
      mathn.  [ruby-core:78893] [Bug #13084]

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/rational.c
    branches/ruby_2_4/test/test_mathn.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/rational.c
===================================================================
--- ruby_2_4/rational.c	(revision 57842)
+++ ruby_2_4/rational.c	(revision 57843)
@@ -2365,11 +2365,22 @@ read_num(const char **s, int numsign, in https://github.com/ruby/ruby/blob/trunk/ruby_2_4/rational.c#L2365
 	    exp = rb_int_uminus(exp);
     }
 
-    if (numsign == '-')
-	*num = rb_rational_uminus(*num);
+    if (numsign == '-') {
+	if (RB_TYPE_P(*num, T_RATIONAL)) {
+	    *num = rb_rational_uminus(*num);
+	}
+	else {
+	    *num = rb_int_uminus(*num);
+	}
+    }
     if (!NIL_P(exp)) {
 	VALUE l = f_expt10(exp);
-	*num = nurat_mul(*num, l);
+	if (RB_TYPE_P(*num, T_RATIONAL)) {
+	    *num = nurat_mul(*num, l);
+	}
+	else {
+	    *num = rb_int_mul(*num, l);
+	}
     }
     return 1;
 }
@@ -2395,8 +2406,14 @@ read_rat_nos(const char **s, int sign, i https://github.com/ruby/ruby/blob/trunk/ruby_2_4/rational.c#L2406
 	(*s)++;
 	if (!read_den(s, strict, &den))
 	    return 0;
-	if (!(FIXNUM_P(den) && FIX2LONG(den) == 1))
-	    *num = nurat_div(*num, den);
+	if (!(FIXNUM_P(den) && FIX2LONG(den) == 1)) {
+	    if (RB_TYPE_P(*num, T_RATIONAL)) {
+		*num = nurat_div(*num, den);
+	    }
+	    else {
+		*num = rb_int_div(*num, den);
+	    }
+	}
     }
     return 1;
 }
Index: ruby_2_4/test/test_mathn.rb
===================================================================
--- ruby_2_4/test/test_mathn.rb	(revision 57842)
+++ ruby_2_4/test/test_mathn.rb	(revision 57843)
@@ -180,4 +180,13 @@ class TestMathn < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/test_mathn.rb#L180
       assert_equal((-13/5), (-13/5).round(2, half: :down))
     EOS
   end
+
+  def test_rational
+    assert_separately(%w[-rmathn], "#{<<-"begin;"}\n#{<<-"end;"}", ignore_stderr: true)
+    begin;
+      assert_equal(-5, "-5".to_r)
+      assert_equal(1, "5/5".to_r)
+      assert_equal(5, "5e0".to_r)
+    end;
+  end
 end
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 57842)
+++ ruby_2_4/version.h	(revision 57843)
@@ -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 10
+#define RUBY_PATCHLEVEL 11
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3

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


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

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