Maintenance of Ruby 2.0.0 ended on February 24, 2016. Read more

In Files

  • mathn.rb

Parent

Class/Module Index [+]

Quicksearch

Numeric

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.

Author: Keiju ISHITSUKA (SHL Japan Inc.)