class Numerals::RationalConversion
Public Instance Methods
exact?(value, options={})
click to toggle source
# File lib/numerals/conversions/rational.rb, line 25 def exact?(value, options={}) true end
number_of_digits(value, options={})
click to toggle source
# File lib/numerals/conversions/rational.rb, line 21 def number_of_digits(value, options={}) return 0 # this is needed only for non-exact values end
number_to_numeral(number, mode, rounding)
click to toggle source
# File lib/numerals/conversions/rational.rb, line 29 def number_to_numeral(number, mode, rounding) q = [number.numerator, number.denominator] numeral = Numerals::Numeral.from_quotient(q) numeral = rounding.round(numeral) # unless rounding.free? numeral end
numeral_to_number(numeral, mode)
click to toggle source
# File lib/numerals/conversions/rational.rb, line 36 def numeral_to_number(numeral, mode) Rational(*numeral.to_quotient) end
order_of_magnitude(value, options={})
click to toggle source
# File lib/numerals/conversions/rational.rb, line 12 def order_of_magnitude(value, options={}) base = options[:base] || 10 if base == 10 Math.log10(value.abs).floor + 1 else (Math.log(value.abs)/Math.log(base)).floor + 1 end end
read(numeral, exact_input, approximate_simplified)
click to toggle source
# File lib/numerals/conversions/rational.rb, line 48 def read(numeral, exact_input, approximate_simplified) Rational(*numeral.to_quotient) end
type()
click to toggle source
# File lib/numerals/conversions/rational.rb, line 8 def type Rational end
write(number, exact_input, output_rounding)
click to toggle source
# File lib/numerals/conversions/rational.rb, line 40 def write(number, exact_input, output_rounding) output_base = output_rounding.base q = [number.numerator, number.denominator] numeral = Numerals::Numeral.from_quotient(q, base: output_base) numeral = output_rounding.round(numeral) # unless output_rounding.free? numeral end