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

ruby-changes:46399

From: usa <ko1@a...>
Date: Sun, 30 Apr 2017 22:27:25 +0900 (JST)
Subject: [ruby-changes:46399] usa:r58513 (ruby_2_3): merge revision(s) 55604, 55612: [Backport #13138]

usa	2017-04-30 22:27:17 +0900 (Sun, 30 Apr 2017)

  New Revision: 58513

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

  Log:
    merge revision(s) 55604,55612: [Backport #13138]
    
    * numeric.c (flo_round): [EXPERIMENTAL] adjust the case that the
      receiver is close to the exact but unrepresentable middle value
      of two values in the given precision.
      http://d.hatena.ne.jp/hnw/20160702
    
    numeric.c: round as double
    
    * numeric.c (flo_round): compare as double, not long double with
      i387.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/numeric.c
    branches/ruby_2_3/test/ruby/test_float.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/numeric.c
===================================================================
--- ruby_2_3/numeric.c	(revision 58512)
+++ ruby_2_3/numeric.c	(revision 58513)
@@ -1786,7 +1786,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_3/numeric.c#L1786
 flo_round(int argc, VALUE *argv, VALUE num)
 {
     VALUE nd;
-    double number, f;
+    double number, f, x;
     int ndigits = 0;
     int binexp;
     enum {float_dig = DBL_DIG+2};
@@ -1828,8 +1828,14 @@ flo_round(int argc, VALUE *argv, VALUE n https://github.com/ruby/ruby/blob/trunk/ruby_2_3/numeric.c#L1828
 	return DBL2NUM(0);
     }
     f = pow(10, ndigits);
-    return DBL2NUM(round(number * f) / f);
-}
+    x = round(number * f);
+    if (x > 0) {
+	if ((double)((x + 0.5) / f) <= number) x += 1;
+    }
+    else {
+	if ((double)((x - 0.5) / f) >= number) x -= 1;
+    }
+    return DBL2NUM(x / f);}
 
 /*
  *  call-seq:
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 58512)
+++ ruby_2_3/version.h	(revision 58513)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.5"
-#define RUBY_RELEASE_DATE "2017-04-09"
-#define RUBY_PATCHLEVEL 303
+#define RUBY_RELEASE_DATE "2017-04-30"
+#define RUBY_PATCHLEVEL 304
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 4
-#define RUBY_RELEASE_DAY 9
+#define RUBY_RELEASE_DAY 30
 
 #include "ruby/version.h"
 
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 58512)
+++ ruby_2_3/ChangeLog	(revision 58513)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Sun Apr 30 22:24:25 2017  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (flo_round): [EXPERIMENTAL] adjust the case that the
+	  receiver is close to the exact but unrepresentable middle value
+	  of two values in the given precision.
+	  http://d.hatena.ne.jp/hnw/20160702
+
 Sun Apr  9 22:21:23 2017  NAKAMURA Usaku  <usa@r...>
 
 	thread.c: rb_thread_fd_close [ci skip]
Index: ruby_2_3/test/ruby/test_float.rb
===================================================================
--- ruby_2_3/test/ruby/test_float.rb	(revision 58512)
+++ ruby_2_3/test/ruby/test_float.rb	(revision 58513)
@@ -442,6 +442,11 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_float.rb#L442
     assert_raise(TypeError) {1.0.round(nil)}
     def (prec = Object.new).to_int; 2; end
     assert_equal(1.0, 0.998.round(prec))
+
+    assert_equal(+5.02, +5.015.round(2))
+    assert_equal(-5.02, -5.015.round(2))
+    assert_equal(+1.26, +1.255.round(2))
+    assert_equal(-1.26, -1.255.round(2))
   end
 
   VS = [
Index: ruby_2_3
===================================================================
--- ruby_2_3	(revision 58512)
+++ ruby_2_3	(revision 58513)

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r55604

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

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