summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-26 15:49:47 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-26 15:49:47 +0000
commitdca0b4177706c2cd9cda0d38af1b82752982e158 (patch)
tree127949dd094e102c5fde0dd73066c2e397134f34 /ext/bigdecimal
parent079fb8d4c369cfc7d450d6e4d02b112596dcb5ee (diff)
* ext/bigdecimal/lib/bigdecimal/util.rb (Rational#to_d):
zero or negative precision is error. fixes #5098. [ruby-dev:44210] * test/bigdecimal/test_bigdecimal_util.rb: add test for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/util.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb
index 1e4bbbb..b27e64c 100644
--- a/ext/bigdecimal/lib/bigdecimal/util.rb
+++ b/ext/bigdecimal/lib/bigdecimal/util.rb
@@ -95,11 +95,11 @@ class Rational < Numeric
# # => #<BigDecimal:1a52bd8,'0.3142857142 8571427937 0154144999 105E1',45(63)>
# r.to_d(3)
# # => #<BigDecimal:1a44d08,'0.314E1',18(36)>
- def to_d(nFig=0)
- num = self.numerator.to_s
- if nFig<=0
- nFig = BigDecimal.double_fig*2+1
+ def to_d(precision)
+ if precision <= 0
+ raise ArgumentError, "negative precision"
end
- BigDecimal.new(num).div(self.denominator,nFig)
+ num = self.numerator
+ BigDecimal(num).div(self.denominator, precision)
end
end