Type:
Class

mathn

mathn is a library for changing the way Ruby does math. If you need more precise rounding with multiple division or exponentiation operations, then mathn is the right tool.

Without mathn:

3 / 2 => 1 # Integer

With mathn:

3 / 2 => 3/2 # Rational

mathn features late rounding and lacks truncation of intermediate results:

Without mathn:

20 / 9 * 3 * 14 / 7 * 3 / 2 # => 18

With mathn:

20 / 9 * 3 * 14 / 7 * 3 / 2 # => 20

When you require 'mathn', the libraries for Prime, CMath, Matrix and Vector are also loaded.

Copyright

Author: Keiju ISHITSUKA (SHL Japan Inc.)

Document-class: FloatDomainError

Raised when attempting to convert special float values (in particular infinite or NaN) to numerical classes which don't support them.

Float::INFINITY.to_r

raises the exception:

FloatDomainError: Infinity
zero?
  • References/Ruby on Rails/Ruby/Classes/Numeric

num.zero? â true or false Instance Public methods Returns true

2025-01-10 15:47:30
singleton_method_added
  • References/Ruby on Rails/Ruby/Classes/Numeric

singleton_method_added(p1) Instance Public methods Trap attempts to add methods

2025-01-10 15:47:30
abs
  • References/Ruby on Rails/Ruby/Classes/Numeric

num.abs â numeric Instance Public methods Returns the absolute value

2025-01-10 15:47:30
rectangular
  • References/Ruby on Rails/Ruby/Classes/Numeric

num.rect â array Instance Public methods Returns an array; [num, 0].

2025-01-10 15:47:30
modulo
  • References/Ruby on Rails/Ruby/Classes/Numeric

num.modulo(numeric) â real Instance Public methods x

2025-01-10 15:47:30
phase
  • References/Ruby on Rails/Ruby/Classes/Numeric

num.phase â 0 or float Instance Public methods Returns 0 if the value is positive

2025-01-10 15:47:30
denominator
  • References/Ruby on Rails/Ruby/Classes/Numeric

num.denominator â integer Instance Public methods Returns the denominator

2025-01-10 15:47:30
ceil
  • References/Ruby on Rails/Ruby/Classes/Numeric

num.ceil â integer Instance Public methods Returns the smallest Integer

2025-01-10 15:47:30
<=>
  • References/Ruby on Rails/Ruby/Classes/Numeric

number other â 0 or nil Instance Public methods Returns zero if number

2025-01-10 15:47:30
truncate
  • References/Ruby on Rails/Ruby/Classes/Numeric

num.truncate â integer Instance Public methods Returns num truncated

2025-01-10 15:47:30