Module

Math

Inheritance

The Math module contains module functions for basic trigonometric and transcendental functions. See class Float for a list of constants that define Ruby‘s floating point accuracy.

Constants

Name   Description
E = rb_float_new(exp(1.0))
E = rb_float_new(M_E)
PI = rb_float_new(atan(1.0)*4.0)
PI = rb_float_new(M_PI)

Aliases

Method Alias Description
acos → acos!
acosh → acosh!
asin → asin!
asinh → asinh!
atan → atan!
atan2 → atan2!
atanh → atanh!
cos → cos!
cosh → cosh!
exp → exp!
log → log!
log10 → log10!
sin → sin!
sinh → sinh!
sqrt → sqrt!
tan → tan!
tanh → tanh!

Methods

Class

Visibility Signature
public acos (p1)
public acosh (p1)
public asin (p1)
public asinh (p1)
public atan (p1)
public atan2 (p1, p2)
public atanh (p1)
public cos (p1)
public cosh (p1)
public erf (p1)
public erfc (p1)
public exp (p1)
public frexp (p1)
public hypot (p1, p2)
public ldexp (p1, p2)
public log (p1)
public log10 (p1)
public sin (p1)
public sinh (p1)
public sqrt (p1)
public tan (p1)
public tanh (p1)

Instance

Visibility Signature
public acos (z)
public acosh (z)
public asin (z)
public asinh (z)
public atan (z)
public atan2 (y,x)
public atanh (z)
public cos (z)
public cosh (z)
public exp (z)
public log (z)
public log10 (z)
public rsqrt (a)
public sin (z)
public sinh (z)
public sqrt (z)
public sqrt (a)
public tan (z)
public tanh (z)

Class Method Detail

Math.acos(x) => float

Computes the arc cosine of x. Returns 0..PI.

Math.acosh(x) => float

Computes the inverse hyperbolic cosine of x.

Math.asin(x) => float

Computes the arc sine of x. Returns -{PI/2} .. {PI/2}.

Math.asinh(x) => float

Computes the inverse hyperbolic sine of x.

Math.atan(x) => float

Computes the arc tangent of x. Returns -{PI/2} .. {PI/2}.

Math.atan2(y, x) => float

Computes the arc tangent given y and x. Returns -PI..PI.

Math.atanh(x) => float

Computes the inverse hyperbolic tangent of x.

Math.cos(x) => float

Computes the cosine of x (expressed in radians). Returns -1..1.

Math.cosh(x) => float

Computes the hyperbolic cosine of x (expressed in radians).

Math.erf(x) => float

Calculates the error function of x.

Math.erfc(x) => float

Calculates the complementary error function of x.

Math.exp(x) => float

Returns e**x.

Math.frexp(numeric) => [ fraction, exponent ]

Returns a two-element array containing the normalized fraction (a Float) and exponent (a Fixnum) of numeric.

   fraction, exponent = Math.frexp(1234)   #=> [0.6025390625, 11]
   fraction * 2**exponent                  #=> 1234.0

Math.hypot(x, y) => float

Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with sides x and y.

   Math.hypot(3, 4)   #=> 5.0

Math.ldexp(flt, int) → float

Returns the value of flt*(2**int).

   fraction, exponent = Math.frexp(1234)
   Math.ldexp(fraction, exponent)   #=> 1234.0

Math.log(numeric) => float

Returns the natural logarithm of numeric.

Math.log10(numeric) => float

Returns the base 10 logarithm of numeric.

Math.sin(x) => float

Computes the sine of x (expressed in radians). Returns -1..1.

Math.sinh(x) => float

Computes the hyperbolic sine of x (expressed in radians).

Math.sqrt(numeric) => float

Returns the non-negative square root of numeric.

Math.tan(x) => float

Returns the tangent of x (expressed in radians).

Math.tanh() => float

Computes the hyperbolic tangent of x (expressed in radians).

Instance Method Detail

acos(z)

acosh(z)

asin(z)

asinh(z)

atan(z)

atan2(y,x)

atanh(z)

cos(z)

Redefined to handle a Complex argument.

cosh(z)

exp(z)

Redefined to handle a Complex argument.

log(z)

Redefined to handle a Complex argument.

log10(z)

Redefined to handle a Complex argument.

rsqrt(a)

sin(z)

Redefined to handle a Complex argument.

sinh(z)

sqrt(z)

Redefined to handle a Complex argument.

sqrt(a)

tan(z)

Redefined to handle a Complex argument.

tanh(z)