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

ruby-changes:45072

From: mrkn <ko1@a...>
Date: Thu, 22 Dec 2016 00:35:36 +0900 (JST)
Subject: [ruby-changes:45072] mrkn:r57145 (trunk): bigdecimal: version 1.3.0

mrkn	2016-12-22 00:35:29 +0900 (Thu, 22 Dec 2016)

  New Revision: 57145

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

  Log:
    bigdecimal: version 1.3.0
    
    Import bigdecimal version 1.3.0.  The full commit log is here:
    
      https://github.com/ruby/bigdecimal/compare/v1.3.0.pre.2...v1.3.0

  Modified files:
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/ext/bigdecimal/bigdecimal.gemspec
    trunk/ext/bigdecimal/lib/bigdecimal/math.rb
    trunk/ext/bigdecimal/lib/bigdecimal/util.rb
    trunk/test/bigdecimal/test_bigdecimal.rb
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 57144)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 57145)
@@ -1082,10 +1082,48 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1082
     assert_equal(BigDecimal('-7.1364'), BigDecimal('-7.1364499').round(4, half: :down))
   end
 
+  def test_round_half_nil
+    x = BigDecimal.new("2.5")
+
+    BigDecimal.save_rounding_mode do
+      BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_UP)
+      assert_equal(3, x.round(0, half: nil))
+    end
+
+    BigDecimal.save_rounding_mode do
+      BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_DOWN)
+      assert_equal(2, x.round(0, half: nil))
+    end
+
+    BigDecimal.save_rounding_mode do
+      BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_UP)
+      assert_equal(3, x.round(0, half: nil))
+    end
+
+    BigDecimal.save_rounding_mode do
+      BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_DOWN)
+      assert_equal(2, x.round(0, half: nil))
+    end
+
+    BigDecimal.save_rounding_mode do
+      BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_EVEN)
+      assert_equal(2, x.round(0, half: nil))
+    end
+
+    BigDecimal.save_rounding_mode do
+      BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_CEILING)
+      assert_equal(3, x.round(0, half: nil))
+    end
+
+    BigDecimal.save_rounding_mode do
+      BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_FLOOR)
+      assert_equal(2, x.round(0, half: nil))
+    end
+  end
+
   def test_round_half_invalid_option
     assert_raise_with_message(ArgumentError, "invalid rounding mode: invalid") { BigDecimal('12.5').round(half: :invalid) }
     assert_raise_with_message(ArgumentError, "invalid rounding mode: invalid") { BigDecimal('2.15').round(1, half: :invalid) }
-    assert_raise_with_message(ArgumentError, "invalid rounding mode: nil") { BigDecimal('12.5').round(half: nil) }
   end
 
   def test_truncate
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 57144)
+++ ext/bigdecimal/bigdecimal.c	(revision 57145)
@@ -335,15 +335,18 @@ BigDecimal_double_fig(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L335
     return INT2FIX(VpDblFig());
 }
 
-/* call-seq:
- * precs
+/*  call-seq:
+ *     big_decimal.precs  ->  array
+ *
+ *  Returns an Array of two Integer values.
  *
- * Returns an Array of two Integer values.
+ *  The first value is the current number of significant digits in the
+ *  BigDecimal. The second value is the maximum number of significant digits
+ *  for the BigDecimal.
  *
- * The first value is the current number of significant digits in the
- * BigDecimal. The second value is the maximum number of significant digits
- * for the BigDecimal.
+ *     BigDecimal('5').precs #=> [9, 18]
  */
+
 static VALUE
 BigDecimal_prec(VALUE self)
 {
@@ -456,7 +459,7 @@ check_rounding_mode_option(VALUE const o https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L459
         goto noopt;
 
     mode = rb_hash_lookup2(opts, ID2SYM(id_half), Qundef);
-    if (mode == Qundef)
+    if (mode == Qundef || NIL_P(mode))
         goto noopt;
 
     if (SYMBOL_P(mode))
@@ -478,6 +481,7 @@ check_rounding_mode_option(VALUE const o https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L481
             return VP_ROUND_HALF_EVEN;
         else if (strncasecmp(s, "down", 4) == 0)
             return VP_ROUND_HALF_DOWN;
+        break;
       default:
         break;
     }
@@ -901,13 +905,14 @@ BigDecimal_coerce(VALUE self, VALUE othe https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L905
 }
 
 /*
- * call-seq: +@
+ * call-seq:
+ *    +big_decimal  ->  big_decimal
  *
  * Return self.
  *
- * e.g.
- *   b = +a  # b == a
+ *     +BigDecimal('5')  #=> 0.5e1
  */
+
 static VALUE
 BigDecimal_uplus(VALUE self)
 {
@@ -1218,14 +1223,14 @@ BigDecimal_ge(VALUE self, VALUE r) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1223
 }
 
 /*
- * call-seq: -@
+ *  call-seq:
+ *     -big_decimal  ->  big_decimal
  *
- * Return the negation of self.
+ *  Return the negation of self.
  *
- * e.g.
- *   b = -a
- *   b == a * -1
+ *    -BigDecimal('5')  #=> -0.5e1
  */
+
 static VALUE
 BigDecimal_neg(VALUE self)
 {
@@ -1672,11 +1677,16 @@ BigDecimal_mult2(VALUE self, VALUE b, VA https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1677
     }
 }
 
-/* Returns the absolute value, as a BigDecimal.
+/*
+ *  call-seq:
+ *     big_decimal.abs  ->  big_decimal
  *
- *   BigDecimal('5').abs #=> 5
- *   BigDecimal('-3').abs #=> 3
+ *  Returns the absolute value, as a BigDecimal.
+ *
+ *     BigDecimal('5').abs  #=> 0.5e1
+ *     BigDecimal('-3').abs #=> 0.3e1
  */
+
 static VALUE
 BigDecimal_abs(VALUE self)
 {
Index: ext/bigdecimal/bigdecimal.gemspec
===================================================================
--- ext/bigdecimal/bigdecimal.gemspec	(revision 57144)
+++ ext/bigdecimal/bigdecimal.gemspec	(revision 57145)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.gemspec#L1
 # coding: utf-8
-_VERSION = '1.3.0.pre.2'
+_VERSION = '1.3.0'
 
 Gem::Specification.new do |s|
   s.name          = "bigdecimal"
Index: ext/bigdecimal/lib/bigdecimal/util.rb
===================================================================
--- ext/bigdecimal/lib/bigdecimal/util.rb	(revision 57144)
+++ ext/bigdecimal/lib/bigdecimal/util.rb	(revision 57145)
@@ -13,7 +13,7 @@ class Integer < Numeric https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L13
   #     require 'bigdecimal/util'
   #
   #     42.to_d
-  #     # => #<BigDecimal:1008ef070,'0.42E2',9(36)>
+  #     # => 0.42e2
   #
   def to_d
     BigDecimal(self)
@@ -34,7 +34,7 @@ class Float < Numeric https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L34
   #     require 'bigdecimal/util'
   #
   #     0.5.to_d
-  #     # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
+  #     # => 0.5e0
   #
   def to_d(precision=nil)
     BigDecimal(self, precision || Float::DIG)
@@ -55,7 +55,7 @@ class String https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L55
   #     require 'bigdecimal/util'
   #
   #     "0.5".to_d
-  #     # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
+  #     # => 0.5e0
   #
   def to_d
     BigDecimal(self)
@@ -117,7 +117,7 @@ class Rational < Numeric https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L117
   #   r = (22/7.0).to_r
   #   # => (7077085128725065/2251799813685248)
   #   r.to_d(3)
-  #   # => #<BigDecimal:1a44d08,'0.314E1',18(36)>
+  #   # => 0.314e1
   def to_d(precision)
     if precision <= 0
       raise ArgumentError, "negative precision"
Index: ext/bigdecimal/lib/bigdecimal/math.rb
===================================================================
--- ext/bigdecimal/lib/bigdecimal/math.rb	(revision 57144)
+++ ext/bigdecimal/lib/bigdecimal/math.rb	(revision 57145)
@@ -26,7 +26,7 @@ require 'bigdecimal' https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/math.rb#L26
 #   include BigMath
 #
 #   a = BigDecimal((PI(100)/2).to_s)
-#   puts sin(a,100) # => 0.10000000000000000000......E1
+#   puts sin(a,100) # => 0.99999999999999999999......e0
 #
 module BigMath
   module_function
@@ -38,7 +38,7 @@ module BigMath https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/math.rb#L38
   # precision, +numeric+.
   #
   #   BigMath.sqrt(BigDecimal.new('2'), 16).to_s
-  #   #=> "0.1414213562373095048801688724E1"
+  #   #=> "0.1414213562373095048801688724e1"
   #
   def sqrt(x, prec)
     x.sqrt(prec)
@@ -53,7 +53,7 @@ module BigMath https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/math.rb#L53
   # If +decimal+ is Infinity or NaN, returns NaN.
   #
   #   BigMath.sin(BigMath.PI(5)/4, 5).to_s
-  #   #=> "0.70710678118654752440082036563292800375E0"
+  #   #=> "0.70710678118654752440082036563292800375e0"
   #
   def sin(x, prec)
     raise ArgumentError, "Zero or negative precision for sin" if prec <= 0
@@ -97,7 +97,7 @@ module BigMath https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/math.rb#L97
   # If +decimal+ is Infinity or NaN, returns NaN.
   #
   #   BigMath.cos(BigMath.PI(4), 16).to_s
-  #   #=> "-0.999999999999999999999999999999856613163740061349E0"
+  #   #=> "-0.999999999999999999999999999999856613163740061349e0"
   #
   def cos(x, prec)
     raise ArgumentError, "Zero or negative precision for cos" if prec <= 0
@@ -141,7 +141,7 @@ module BigMath https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/math.rb#L141
   # If +decimal+ is NaN, returns NaN.
   #
   #   BigMath.atan(BigDecimal.new('-1'), 16).to_s
-  #   #=> "-0.785398163397448309615660845819878471907514682065E0"
+  #   #=> "-0.785398163397448309615660845819878471907514682065e0"
   #
   def atan(x, prec)
     raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
@@ -178,7 +178,7 @@ module BigMath https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/math.rb#L178
   # +numeric+.
   #
   #   BigMath.PI(10).to_s
-  #   #=> "0.3141592653589793238462643388813853786957412E1"
+  #   #=> "0.3141592653589793238462643388813853786957412e1"
   #
   def PI(prec)
     raise ArgumentError, "Zero or negative precision for PI" if prec <= 0
@@ -223,7 +223,7 @@ module BigMath https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/math.rb#L223
   # digits of precision, +numeric+.
   #
   #   BigMath.E(10).to_s
-  #   #=> "0.271828182845904523536028752390026306410273E1"
+  #   #=> "0.271828182845904523536028752390026306410273e1"
   #
   def E(prec)
     raise ArgumentError, "Zero or negative precision for E" if prec <= 0

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

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