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

ruby-changes:44965

From: mrkn <ko1@a...>
Date: Sat, 10 Dec 2016 11:36:26 +0900 (JST)
Subject: [ruby-changes:44965] mrkn:r57038 (trunk): internal.h: change the default rounding mode to half-up

mrkn	2016-12-10 11:36:16 +0900 (Sat, 10 Dec 2016)

  New Revision: 57038

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

  Log:
    internal.h: change the default rounding mode to half-up
    
    * internal.h (ROUND_DEFAULT): changed to RUBY_NUM_ROUND_HALF_UP.
      [Bug #12958] [ruby-core:78204]
    
    * test/ruby/test_integer.rb: fix assertions for the above change.
    
    * test/ruby/test_rational.rb: ditto.
    
    * test/test_mathn.rb: ditto.

  Modified files:
    trunk/internal.h
    trunk/test/ruby/test_integer.rb
    trunk/test/ruby/test_rational.rb
    trunk/test/test_mathn.rb
Index: test/test_mathn.rb
===================================================================
--- test/test_mathn.rb	(revision 57037)
+++ test/test_mathn.rb	(revision 57038)
@@ -96,17 +96,17 @@ class TestMathn < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_mathn.rb#L96
   def test_round
     assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
       assert_equal( 3, ( 13/5).round)
-      assert_equal( 2, (  5/2).round)
+      assert_equal( 3, (  5/2).round)
       assert_equal( 2, ( 12/5).round)
       assert_equal(-2, (-12/5).round)
-      assert_equal(-2, ( -5/2).round)
+      assert_equal(-3, ( -5/2).round)
       assert_equal(-3, (-13/5).round)
 
       assert_equal( 3, ( 13/5).round(0))
-      assert_equal( 2, (  5/2).round(0))
+      assert_equal( 3, (  5/2).round(0))
       assert_equal( 2, ( 12/5).round(0))
       assert_equal(-2, (-12/5).round(0))
-      assert_equal(-2, ( -5/2).round(0))
+      assert_equal(-3, ( -5/2).round(0))
       assert_equal(-3, (-13/5).round(0))
 
       assert_equal(( 13/5), ( 13/5).round(2))
Index: test/ruby/test_integer.rb
===================================================================
--- test/ruby/test_integer.rb	(revision 57037)
+++ test/ruby/test_integer.rb	(revision 57038)
@@ -187,7 +187,7 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L187
     assert_int_equal(11110, 11111.round(-1))
     assert_int_equal(11100, 11111.round(-2))
     assert_int_equal(+200, +249.round(-2))
-    assert_int_equal(+200, +250.round(-2))
+    assert_int_equal(+300, +250.round(-2))
     assert_int_equal(-200, -249.round(-2))
     assert_int_equal(+200, +249.round(-2, half: :even))
     assert_int_equal(+200, +250.round(-2, half: :even))
@@ -201,7 +201,7 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L201
     assert_int_equal(+200, +250.round(-2, half: :down))
     assert_int_equal(+300, +349.round(-2, half: :down))
     assert_int_equal(+300, +350.round(-2, half: :down))
-    assert_int_equal(-200, -250.round(-2))
+    assert_int_equal(-300, -250.round(-2))
     assert_int_equal(-200, -249.round(-2, half: :even))
     assert_int_equal(-200, -250.round(-2, half: :even))
     assert_int_equal(-300, -349.round(-2, half: :even))
@@ -214,8 +214,8 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L214
     assert_int_equal(-200, -250.round(-2, half: :down))
     assert_int_equal(-300, -349.round(-2, half: :down))
     assert_int_equal(-300, -350.round(-2, half: :down))
-    assert_int_equal(+20 * 10**70, (+25 * 10**70).round(-71))
-    assert_int_equal(-20 * 10**70, (-25 * 10**70).round(-71))
+    assert_int_equal(+30 * 10**70, (+25 * 10**70).round(-71))
+    assert_int_equal(-30 * 10**70, (-25 * 10**70).round(-71))
     assert_int_equal(+20 * 10**70, (+25 * 10**70 - 1).round(-71))
     assert_int_equal(-20 * 10**70, (-25 * 10**70 + 1).round(-71))
     assert_int_equal(+40 * 10**70, (+35 * 10**70).round(-71))
Index: test/ruby/test_rational.rb
===================================================================
--- test/ruby/test_rational.rb	(revision 57037)
+++ test/ruby/test_rational.rb	(revision 57038)
@@ -598,10 +598,10 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L598
 
   def test_trunc
     [[Rational(13, 5),  [ 2,  3,  2,  3,  3,  3,  3]], #  2.6
-     [Rational(5, 2),   [ 2,  3,  2,  2,  2,  3,  2]], #  2.5
+     [Rational(5, 2),   [ 2,  3,  2,  3,  2,  3,  2]], #  2.5
      [Rational(12, 5),  [ 2,  3,  2,  2,  2,  2,  2]], #  2.4
      [Rational(-12,5),  [-3, -2, -2, -2, -2, -2, -2]], # -2.4
-     [Rational(-5, 2),  [-3, -2, -2, -2, -2, -3, -2]], # -2.5
+     [Rational(-5, 2),  [-3, -2, -2, -3, -2, -3, -2]], # -2.5
      [Rational(-13, 5), [-3, -2, -2, -3, -3, -3, -3]], # -2.6
     ].each do |i, a|
       s = proc {i.inspect}
Index: internal.h
===================================================================
--- internal.h	(revision 57037)
+++ internal.h	(revision 57038)
@@ -1144,7 +1144,7 @@ void Init_newline(void); https://github.com/ruby/ruby/blob/trunk/internal.h#L1144
 #define INT_NEGATIVE_P(x) (FIXNUM_P(x) ? FIXNUM_NEGATIVE_P(x) : BIGNUM_NEGATIVE_P(x))
 
 #ifndef ROUND_DEFAULT
-# define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_EVEN
+# define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP
 #endif
 enum ruby_num_rounding_mode {
     RUBY_NUM_ROUND_HALF_UP,

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

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