From b8e804e410b9088fc7921fcf8b6a92a4fbb3006a Mon Sep 17 00:00:00 2001 From: Maciej Rzasa 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(-) (limited to 'ext/bigdecimal') 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. -- cgit v1.2.1