Math

A module that supports floating point calculations.

Module Functions

Math.acos(x)
Math.asin(x)
Math.atan(x)

Returns the value of the inverse trigonometric functions of x in radians.

Values that can be returned have ranges of [0, +π], [-π/2, +π/2], and (-π/2, +π/2) respectively.

In acos(x), and asin(x), x must be in the range -1.0 <= x <= 1 (normally returns NaN).

acos() and asin() will throw an Errno::EDOM exception for arguments out of range.

Math.atan2(y, x)

Returns the arctangent of y/x in the range [-π, π].

Math.acosh(x)
Math.asinh(x)
Math.atanh(x)

Returns the value of the inverse hyperbolic functions of x.

asinh(x) = log(x + sqrt(x * x + 1))
acosh(x) = log(x + sqrt(x * x - 1)) [x >= 1]
atanh(x) = log((1+x)/(1-x)) / 2     [-1 < x < 1]

In acosh(x), x must be >= 1 (normally throws an Errno::EDOM exception).

In atanh(x), x must be in the range -1.0 < x < 1 (normally throws an Errno::EDOM exception).

Math.cos(x)
Math.sin(x)
Math.tan(x)

Returns the value of the trigonometric functions of x in radians, in the range [-1, 1].

Math.cosh(x)
Math.sinh(x)
Math.tanh(x)

Returns the value of the hyperbolic functions of x.

cosh(x) = (exp(x) + exp(-x)) / 2
sinh(x) = (exp(x) - exp(-x)) / 2
tanh(x) = sinh(x) / cosh(x)
Math.erf(x)
Math.erfc(x)

Returns the values of the error function (erf) and complementary error function (erfc) of x.

Math.exp(x)

Returns the value of the exponential function of x.

Math.frexp(x)

Returns the exponent and mantissa of the real number x.

Math.hypot(x, y)

Returns sqrt(x*x + y*y).

Math.ldexp(x, exp)

Returns the real number x multiplied by 2 to the power of exp.

Math.log(x)

Returns the natural logarithm of x.

x must be a positive value (normally returns NaN for negative values and -Infinity for 0).

Negative arguments out of range throw Errno::EDOM exceptions, while a 0 argument throws an Errno::ERANGE exception.

Math.log10(x)

Returns the common logarithm of x.

x must be a positive value (normally returns NaN for negative values and -Infinity for 0).

Negative arguments out of range throw Errno::EDOM exceptions, while a 0 argument throws an Errno::ERANGE exception.

Math.sqrt(x)

Returns the square root of x. When x is a negative value, throws an ArgumentError exception.

Normally, when x is negative, throws an Errno::EDOM exception.

Definitions

E

The natural logarithmic base.

p Math::E
# => 2.718281828
PI

The circle ratio.

p Math::PI
# => 3.141592654
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)