summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authorMaciej Rzasa <maciejrzasa@gmail.com>2022-07-29 11:33:23 +0200
committergit <svn-admin@ruby-lang.org>2022-09-28 09:29:49 +0900
commitb8e804e410b9088fc7921fcf8b6a92a4fbb3006a (patch)
tree24500cb70ab74657555285ed59b32370901fce62 /ext/bigdecimal
parenta58cbddd57152a3a4712c6b37b6efa3c108847e7 (diff)
[ruby/bigdecimal] Document precision=0 and ndigits=0 for converting from Float
https://github.com/ruby/bigdecimal/commit/4f0894c6c0
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c3
-rw-r--r--ext/bigdecimal/lib/bigdecimal/util.rb6
2 files changed, 8 insertions, 1 deletions
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)
* 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
#
# 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.