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
fdiv

num.fdiv(numeric) â float Instance Public methods Returns float division

2015-04-23 00:15:57
<=>

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

2015-04-22 23:17:41
truncate

num.truncate â integer Instance Public methods Returns num truncated

2015-04-23 02:01:12
+@

+num â num Instance Public methods Unary PlusâReturns the receiver's value

2015-04-22 23:09:44
remainder

num.remainder(numeric) â real Instance Public methods

2015-04-23 01:26:58
divmod

num.divmod(numeric) â array Instance Public methods Returns an array containing

2015-04-23 00:07:59
eql?

num.eql?(numeric) â true or false Instance Public methods Returns true

2015-04-23 00:10:49
rect

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

2015-04-23 01:12:48
integer?

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

2015-04-23 00:34:50
polar

num.polar â array Instance Public methods Returns an array; [num.abs, num

2015-04-23 00:55:33