Changed according to Tadashi Saito's advice.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d3ce235bab
commit
f64d6232ab
@ -1,10 +1,10 @@
|
|||||||
#
|
#
|
||||||
# BigDecimal <-> Rational
|
# BigDecimal <-> Rational
|
||||||
#
|
#
|
||||||
class BigDecimal
|
class BigDecimal < Numeric
|
||||||
# Convert BigDecimal to Rational
|
# Convert BigDecimal to Rational
|
||||||
def to_r
|
def to_r
|
||||||
sign,digits,base,power = self.to_parts
|
sign,digits,base,power = self.split
|
||||||
numerator = sign*digits.to_i
|
numerator = sign*digits.to_i
|
||||||
denomi_power = power - digits.size # base is always 10
|
denomi_power = power - digits.size # base is always 10
|
||||||
if denomi_power < 0
|
if denomi_power < 0
|
||||||
@ -12,11 +12,11 @@ class BigDecimal
|
|||||||
else
|
else
|
||||||
denominator = base ** denomi_power
|
denominator = base ** denomi_power
|
||||||
end
|
end
|
||||||
Rational.new(numerator,denominator)
|
Rational(numerator,denominator)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Rational
|
class Rational < Numeric
|
||||||
# Convert Rational to BigDecimal
|
# Convert Rational to BigDecimal
|
||||||
# to_d returns an array [quotient,residue]
|
# to_d returns an array [quotient,residue]
|
||||||
def to_d(nFig=0)
|
def to_d(nFig=0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user