From a0e438cd3c28d2eaf4efa18243d5b6edafa14d88 Mon Sep 17 00:00:00 2001 From: mrkn Date: Sun, 2 Dec 2018 05:21:54 +0000 Subject: Import bigdecimal-1.4.0.pre-20181130a * https://github.com/ruby/bigdecimal/compare/74d25ef..v1.4.0.pre.20181130a git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/lib/bigdecimal/jacobian.rb | 3 +++ ext/bigdecimal/lib/bigdecimal/util.rb | 30 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'ext/bigdecimal/lib/bigdecimal') diff --git a/ext/bigdecimal/lib/bigdecimal/jacobian.rb b/ext/bigdecimal/lib/bigdecimal/jacobian.rb index 9cad06c09b..84c50248b7 100644 --- a/ext/bigdecimal/lib/bigdecimal/jacobian.rb +++ b/ext/bigdecimal/lib/bigdecimal/jacobian.rb @@ -21,6 +21,9 @@ # # fx is f.values(x). # + +require 'bigdecimal' + module Jacobian module_function diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb index 911fa6fe3a..88f490cb45 100644 --- a/ext/bigdecimal/lib/bigdecimal/util.rb +++ b/ext/bigdecimal/lib/bigdecimal/util.rb @@ -5,6 +5,8 @@ # and provides BigDecimal#to_d and BigDecimal#to_digits. #++ +require 'bigdecimal' +require 'bigdecimal/util.so' class Integer < Numeric # call-seq: @@ -42,8 +44,8 @@ class Float < Numeric # # See also BigDecimal::new. # - def to_d(precision=nil) - BigDecimal(self, precision || Float::DIG) + def to_d(precision=Float::DIG) + BigDecimal(self, precision) end end @@ -64,13 +66,6 @@ class String # # See also BigDecimal::new. # - def to_d - begin - BigDecimal(self) - rescue ArgumentError - BigDecimal(0) - end - end end @@ -132,3 +127,20 @@ class Rational < Numeric BigDecimal(self, precision) end end + + +class NilClass + # call-seq: + # nil.to_d -> bigdecimal + # + # Returns nil represented as a BigDecimal. + # + # require 'bigdecimal' + # require 'bigdecimal/util' + # + # nil.to_d # => 0.0 + # + def to_d + BigDecimal(0) + end +end -- cgit v1.2.1