NumericMath

Overview

NumericMath extends the Numeric class with methods from Math module. The purpose is to increase productivity when using Math module methods interactively. Some might find the simpler approach convenient also for actual programs.

For example, without NumericMath you take “sin” of 1.5 as:

Math.sin( 1.5 )

With NumericMath you do:

1.5.sin

Math module includes many single argument methods, which take the form as above. Two argument methods are mapped, so that first argument is “self” and the second argument becomes the first and only parameter for the new form.

For example, what is originally:

Math.log( 4, 2 )

is with NumericMath:

4.log( 2 )

The mapped methods are also usable as class methods, e.g:

Fixnum.sin( 2 )

The gem file name is “numeric_math”, thus taking NumericMath into use requires:

require 'numeric_math'
...
Fixnum.sin( 0.12 )
2.cos

Mapped methods

List of single argument methods: cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, exp, log2, log10, sqrt, cbrt, frexp, erf, erfc, gamma, lgamma.

List of two argument methods: atan2, log, hypot, ldexp.