Class: Float

Inherits:
Object
  • Object
show all
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

Instance Method Details

#b(base) ⇒ Radix::Float

Takes a Ruby Float and makes it into a Radix::Float as given base.

Parameters:

Returns:


16
17
18
# File 'lib/radix/operator.rb', line 16

def b(base)
  Radix::Float.new(self, base)
end

#to_rRational

Adds a #to_r method to pre-1.9 ruby Rationals.

Returns:

  • (Rational)

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