Class: Float
- Inherits:
-
Object
- Object
- Float
- Defined in:
- lib/radix/operator.rb,
lib/radix/rational.rb
Overview
Adds the b(base) method to this ruby class for quickly creating Radix instances.
Instance Method Summary collapse
-
#b(base) ⇒ Radix::Float
Takes a Ruby Float and makes it into a Radix::Float as given base.
-
#to_r ⇒ Rational
Adds a #to_r method to pre-1.9 ruby Rationals.
Instance Method Details
#b(base) ⇒ Radix::Float
Takes a Ruby Float and makes it into a Radix::Float as given base.
16 17 18 |
# File 'lib/radix/operator.rb', line 16 def b(base) Radix::Float.new(self, base) end |
#to_r ⇒ Rational
Adds a #to_r method to pre-1.9 ruby Rationals.
303 304 305 306 307 308 |
# File 'lib/radix/rational.rb', line 303 def to_r n, f = to_s.split('.') d = (10 ** f.size).to_i n = (n.to_i * d) + f.to_i Rational(n, d) end |