diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-12-02 05:21:54 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-12-02 05:21:54 +0000 |
commit | a0e438cd3c28d2eaf4efa18243d5b6edafa14d88 (patch) | |
tree | c8a0e8d7a8553034c2cc4957890ea48ad7277693 /ext/bigdecimal/lib/bigdecimal | |
parent | 096d362939816b569b22ed3de87c06277ef4c3fb (diff) |
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
Diffstat (limited to 'ext/bigdecimal/lib/bigdecimal')
-rw-r--r-- | ext/bigdecimal/lib/bigdecimal/jacobian.rb | 3 | ||||
-rw-r--r-- | ext/bigdecimal/lib/bigdecimal/util.rb | 30 |
2 files changed, 24 insertions, 9 deletions
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 |