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

ruby-changes:73754

From: Maciej <ko1@a...>
Date: Wed, 28 Sep 2022 09:29:58 +0900 (JST)
Subject: [ruby-changes:73754] b8e804e410 (master): [ruby/bigdecimal] Document precision=0 and ndigits=0 for converting from Float

https://git.ruby-lang.org/ruby.git/commit/?id=b8e804e410

From b8e804e410b9088fc7921fcf8b6a92a4fbb3006a Mon Sep 17 00:00:00 2001
From: Maciej Rzasa <maciejrzasa@g...>
Date: Fri, 29 Jul 2022 11:33:23 +0200
Subject: [ruby/bigdecimal] Document precision=0 and ndigits=0 for converting
 from Float

https://github.com/ruby/bigdecimal/commit/4f0894c6c0
---
 ext/bigdecimal/bigdecimal.c           | 3 +++
 ext/bigdecimal/lib/bigdecimal/util.rb | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 61a8d4d8d5..1483f327a6 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -3500,6 +3500,9 @@ rb_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3500
  *  in the value, the result is rounded to that number of digits,
  *  according to the current rounding mode; see BigDecimal.mode.
  *
+ *  When +ndigits+ is 0, the number of digits to correctly represent a float number
+ *  is determined automatically.
+ *
  *  Returns +value+ converted to a \BigDecimal, depending on the type of +value+:
  *
  *  - Integer, Float, Rational, Complex, or BigDecimal: converted directly:
diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb
index cb645d2a71..ad92f7cfe6 100644
--- a/ext/bigdecimal/lib/bigdecimal/util.rb
+++ b/ext/bigdecimal/lib/bigdecimal/util.rb
@@ -33,12 +33,16 @@ class Float < Numeric https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L33
   #
   # Returns the value of +float+ as a BigDecimal.
   # The +precision+ parameter is used to determine the number of
-  # significant digits for the result (the default is Float::DIG).
+  # significant digits for the result. When +precision+ is set to +0+,
+  # the number of digits to represent the float being converted is determined
+  # automatically.
+  # The default +precision+ is +0+.
   #
   #     require 'bigdecimal'
   #     require 'bigdecimal/util'
   #
   #     0.5.to_d         # => 0.5e0
+  #     1.234.to_d       # => 0.1234e1
   #     1.234.to_d(2)    # => 0.12e1
   #
   # See also BigDecimal::new.
-- 
cgit v1.2.1


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

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