class Numerals::IntegerConversion
Public Instance Methods
exact?(value, options={})
click to toggle source
# File lib/numerals/conversions/integer.rb, line 29 def exact?(value, options={}) true end
number_of_digits(value, options={})
click to toggle source
# File lib/numerals/conversions/integer.rb, line 24 def number_of_digits(value, options={}) # order_of_magnitude(value, options) 0 # this is needed only for non-exact values end
number_to_numeral(number, mode, rounding)
click to toggle source
# File lib/numerals/conversions/integer.rb, line 33 def number_to_numeral(number, mode, rounding) # Rational.numerals_conversion Rational(number), mode, rounding numeral = Numerals::Numeral.from_quotient(number, 1) numeral = rounding.round(numeral) # unless rounding.free? numeral end
numeral_to_number(numeral, mode)
click to toggle source
# File lib/numerals/conversions/integer.rb, line 40 def numeral_to_number(numeral, mode) rational = Rational.numerals_conversion.numeral_to_number numeral, mode if rational.denominator != 1 raise InvalidConversion, "Invalid numeral to rational conversion" end rational.numerator end
order_of_magnitude(value, options={})
click to toggle source
# File lib/numerals/conversions/integer.rb, line 15 def order_of_magnitude(value, options={}) base = options[:base] || 10 if base == 2 && value.respond_to?(:bit_length) value.bit_length else value.to_s(base).size end end
read(numeral, exact_input, approximate_simplified)
click to toggle source
# File lib/numerals/conversions/integer.rb, line 55 def read(numeral, exact_input, approximate_simplified) rational = Rational.numerals_conversion.read numeral, exact_input, approximate_simplified if rational.denominator != 1 raise InvalidConversion, "Invalid numeral to rational conversion" end rational.numerator end
type()
click to toggle source
# File lib/numerals/conversions/integer.rb, line 11 def type Integer end
write(number, exact_input, output_rounding)
click to toggle source
# File lib/numerals/conversions/integer.rb, line 48 def write(number, exact_input, output_rounding) output_base = output_rounding.base numeral = Numerals::Numeral.from_quotient(number, 1, base: output_base) numeral = output_rounding.round(numeral) # unless output_rounding.free? numeral end