Skip to content

module Math

Extended modules

Math

Constants

E = LibM.exp_f64(1.0)

Euler's number (e).

LOG10 = LibM.log_f64(10.0)

LOG2 = LibM.log_f64(2.0)

PI = 3.14159265358979323846

Archimedes' constant (Ï€).

TAU = 6.283185307179586476925

The full circle constant (Ï„), equal to 2Ï€.

Methods

#acos(value)

Calculates the arc cosine of value.

View source

#acos(value : Float64)

Calculates the arc cosine of value.

View source

#acos(value : Float32)

Calculates the arc cosine of value.

View source

#acosh(value : Float32)

Calculates the inverse hyperbolic cosine of value.

View source

#acosh(value : Float64)

Calculates the inverse hyperbolic cosine of value.

View source

#acosh(value)

Calculates the inverse hyperbolic cosine of value.

View source

#asin(value : Float32)

Calculates the arc sine of value.

View source

#asin(value : Float64)

Calculates the arc sine of value.

View source

#asin(value)

Calculates the arc sine of value.

View source

#asinh(value : Float64)

Calculates the inverse hyperbolic sine of value.

View source

#asinh(value)

Calculates the inverse hyperbolic sine of value.

View source

#asinh(value : Float32)

Calculates the inverse hyperbolic sine of value.

View source

#atan(value : Float32)

Calculates the arc tangent of value.

View source

#atan(value : Float64)

Calculates the arc tangent of value.

View source

#atan(value)

Calculates the arc tangent of value.

View source

#atan2(y, x)

Calculates the two-argument arc tangent of the ray from (0, 0) to (x, y).

View source

#atan2(y : Float32, x : Float32)

Calculates the two-argument arc tangent of the ray from (0, 0) to (x, y).

View source

#atan2(y : Float64, x : Float64)

Calculates the two-argument arc tangent of the ray from (0, 0) to (x, y).

View source

#atanh(value)

Calculates the inverse hyperbolic tangent of value.

View source

#atanh(value : Float64)

Calculates the inverse hyperbolic tangent of value.

View source

#atanh(value : Float32)

Calculates the inverse hyperbolic tangent of value.

View source

#besselj(order : Int32, value : Float32)

Calculates the cylindrical Bessel function of the first kind of value for the given order.

View source

#besselj(order, value)

Calculates the cylindrical Bessel function of the first kind of value for the given order.

View source

#besselj(order : Int32, value : Float64)

Calculates the cylindrical Bessel function of the first kind of value for the given order.

View source

#besselj0(value : Float64)

Calculates the cylindrical Bessel function of the first kind of value for order 0.

View source

#besselj0(value)

Calculates the cylindrical Bessel function of the first kind of value for order 0.

View source

#besselj0(value : Float32)

Calculates the cylindrical Bessel function of the first kind of value for order 0.

View source

#besselj1(value)

Calculates the cylindrical Bessel function of the first kind of value for order 1.

View source

#besselj1(value : Float64)

Calculates the cylindrical Bessel function of the first kind of value for order 1.

View source

#besselj1(value : Float32)

Calculates the cylindrical Bessel function of the first kind of value for order 1.

View source

#bessely(order, value)

Calculates the cylindrical Bessel function of the second kind of value for the given order.

View source

#bessely(order : Int32, value : Float64)

Calculates the cylindrical Bessel function of the second kind of value for the given order.

View source

#bessely(order : Int32, value : Float32)

Calculates the cylindrical Bessel function of the second kind of value for the given order.

View source

#bessely0(value : Float32)

Calculates the cylindrical Bessel function of the second kind of value for order 0.

View source

#bessely0(value : Float64)

Calculates the cylindrical Bessel function of the second kind of value for order 0.

View source

#bessely0(value)

Calculates the cylindrical Bessel function of the second kind of value for order 0.

View source

#bessely1(value : Float32)

Calculates the cylindrical Bessel function of the second kind of value for order 1.

View source

#bessely1(value)

Calculates the cylindrical Bessel function of the second kind of value for order 1.

View source

#bessely1(value : Float64)

Calculates the cylindrical Bessel function of the second kind of value for order 1.

View source

#cbrt(value : Float32)

Calculates the cubic root of value.

View source

#cbrt(value : Float64)

Calculates the cubic root of value.

View source

#cbrt(value)

Calculates the cubic root of value.

View source

#copysign(value1 : Float32, value2 : Float32)

Returns the floating-point value with the magnitude of value1 and the sign of value2.

View source

#copysign(value1 : Float64, value2 : Float64)

Returns the floating-point value with the magnitude of value1 and the sign of value2.

View source

#copysign(value1, value2)

Returns the floating-point value with the magnitude of value1 and the sign of value2.

View source

#cos(value : Float32)

Calculates the cosine of value, measured in radians.

View source

#cos(value)

Calculates the cosine of value, measured in radians.

View source

#cos(value : Float64)

Calculates the cosine of value, measured in radians.

View source

#cosh(value)

Calculates the hyperbolic cosine of value.

View source

#cosh(value : Float64)

Calculates the hyperbolic cosine of value.

View source

#cosh(value : Float32)

Calculates the hyperbolic cosine of value.

View source

#erf(value)

Calculates the error function of value.

View source

#erf(value : Float64)

Calculates the error function of value.

View source

#erf(value : Float32)

Calculates the error function of value.

View source

#erfc(value)

Calculates 1 minus the error function of value.

View source

#erfc(value : Float64)

Calculates 1 minus the error function of value.

View source

#erfc(value : Float32)

Calculates 1 minus the error function of value.

View source

#exp(value : Float32)

Calculates the exponential of value.

View source

#exp(value : Float64)

Calculates the exponential of value.

View source

#exp(value : Complex)

Calculates the exponential of value.

require "complex"

Math.exp(4 + 2.i) # => -22.720847417619233 + 49.645957334580565i
View source

#exp(value)

Calculates the exponential of value.

View source

#exp2(value : Float32)

Calculates 2 raised to the power value.

View source

#exp2(value : Float64)

Calculates 2 raised to the power value.

View source

#exp2(value)

Calculates 2 raised to the power value.

View source

#expm1(value)

Calculates the exponential of value, minus 1.

View source

#expm1(value : Float32)

Calculates the exponential of value, minus 1.

View source

#expm1(value : Float64)

Calculates the exponential of value, minus 1.

View source

#frexp(value)

Decomposes the given floating-point value into a normalized fraction and an integral power of two.

View source

#frexp(value : Float32)

Decomposes the given floating-point value into a normalized fraction and an integral power of two.

View source

#frexp(value : Float64)

Decomposes the given floating-point value into a normalized fraction and an integral power of two.

View source

#frexp(value : BigFloat)

Decomposes the given floating-point value into a normalized fraction and an integral power of two.

View source

#gamma(value)

Calculates the gamma function of value.

Note that gamma(n) is same as fact(n - 1) for integer n > 0. However gamma(n) returns float and can be an approximation.

View source

#gamma(value : Float64)

Calculates the gamma function of value.

Note that gamma(n) is same as fact(n - 1) for integer n > 0. However gamma(n) returns float and can be an approximation.

View source

#gamma(value : Float32)

Calculates the gamma function of value.

Note that gamma(n) is same as fact(n - 1) for integer n > 0. However gamma(n) returns float and can be an approximation.

View source

#hypot(value1 : Float64, value2 : Float64)

Calculates the length of the hypotenuse from (0, 0) to (value1, value2).

Equivalent to

Math.sqrt(value1 ** 2 + value2 ** 2)

View source

#hypot(value1 : Float32, value2 : Float32)

Calculates the length of the hypotenuse from (0, 0) to (value1, value2).

Equivalent to

Math.sqrt(value1 ** 2 + value2 ** 2)

View source

#hypot(value1, value2)

Calculates the length of the hypotenuse from (0, 0) to (value1, value2).

Equivalent to

Math.sqrt(value1 ** 2 + value2 ** 2)

View source

#ilogb(value : Float32)

Returns the unbiased base 2 exponent of the given floating-point value.

View source

#ilogb(value : Float64)

Returns the unbiased base 2 exponent of the given floating-point value.

View source

#ilogb(value)

Returns the unbiased base 2 exponent of the given floating-point value.

View source

#ldexp(value, exp)

Multiplies the given floating-point value by 2 raised to the power exp.

View source

#ldexp(value : Float32, exp : Int32)

Multiplies the given floating-point value by 2 raised to the power exp.

View source

#ldexp(value : Float64, exp : Int32)

Multiplies the given floating-point value by 2 raised to the power exp.

View source

#lgamma(value : Float32)

Calculates the logarithmic gamma of value.

Math.lgamma(2.96)
is equivalent to
Math.log(Math.gamma(2.96).abs)

View source

#lgamma(value : Float64)

Calculates the logarithmic gamma of value.

Math.lgamma(2.96)
is equivalent to
Math.log(Math.gamma(2.96).abs)

View source

#lgamma(value)

Calculates the logarithmic gamma of value.

Math.lgamma(2.96)
is equivalent to
Math.log(Math.gamma(2.96).abs)

View source

#log(value, base)

Calculates the logarithm of value to the given base.

View source

#log(value : Float32)

Calculates the natural logarithm of value.

View source

#log(value : Float64)

Calculates the natural logarithm of value.

View source

#log(value : Complex)

Calculates the natural logarithm of value.

require "complex"

Math.log(4 + 2.i) # => 1.4978661367769956 + 0.4636476090008061i
View source

#log(value)

Calculates the natural logarithm of value.

View source

#log10(value)

Calculates the logarithm of value to base 10.

View source

#log10(value : Complex)

Calculates the logarithm of value to base 10.

require "complex"

Math.log10(4 + 2.i) # => 0.6505149978319906 + 0.20135959813668655i
View source

#log10(value : Float64)

Calculates the logarithm of value to base 10.

View source

#log10(value : Float32)

Calculates the logarithm of value to base 10.

View source

#log1p(value)

Calculates the natural logarithm of 1 plus value.

View source

#log1p(value : Float64)

Calculates the natural logarithm of 1 plus value.

View source

#log1p(value : Float32)

Calculates the natural logarithm of 1 plus value.

View source

#log2(value)

Calculates the logarithm of value to base 2.

View source

#log2(value : Float64)

Calculates the logarithm of value to base 2.

View source

#log2(value : Float32)

Calculates the logarithm of value to base 2.

View source

#log2(value : Complex)

Calculates the logarithm of value to base 2.

require "complex"

Math.log2(4 + 2.i) # => 2.1609640474436813 + 0.6689021062254881i
View source

#logb(value : Float32)

Returns the unbiased radix-independent exponent of the given floating-point value.

For Float32 and Float64 this is equivalent to ilogb.

View source

#logb(value : Float64)

Returns the unbiased radix-independent exponent of the given floating-point value.

For Float32 and Float64 this is equivalent to ilogb.

View source

#logb(value)

Returns the unbiased radix-independent exponent of the given floating-point value.

For Float32 and Float64 this is equivalent to ilogb.

View source

#max(value1 : Float32, value2 : Float32)

Returns the greater of value1 and value2.

View source

#max(value1 : Float64, value2 : Float64)

Returns the greater of value1 and value2.

View source

#max(value1, value2)

Returns the greater of value1 and value2.

View source

#min(value1 : Float32, value2 : Float32)

Returns the smaller of value1 and value2.

View source

#min(value1 : Float64, value2 : Float64)

Returns the smaller of value1 and value2.

View source

#min(value1, value2)

Returns the smaller of value1 and value2.

View source

#pw2ceil(v)

Computes the next highest power of 2 of v.

Math.pw2ceil(33) # => 64
View source

#scalbln(value : Float32, exp : Int64)

Returns the floating-point value with its exponent raised by exp.

For Float32 and Float64 this is equivalent to ldexp.

View source

#scalbln(value : Float64, exp : Int64)

Returns the floating-point value with its exponent raised by exp.

For Float32 and Float64 this is equivalent to ldexp.

View source

#scalbln(value, exp)

Returns the floating-point value with its exponent raised by exp.

For Float32 and Float64 this is equivalent to ldexp.

View source

#scalbn(value : Float64, exp : Int32)

Returns the floating-point value with its exponent raised by exp.

For Float32 and Float64 this is equivalent to ldexp.

View source

#scalbn(value, exp)

Returns the floating-point value with its exponent raised by exp.

For Float32 and Float64 this is equivalent to ldexp.

View source

#scalbn(value : Float32, exp : Int32)

Returns the floating-point value with its exponent raised by exp.

For Float32 and Float64 this is equivalent to ldexp.

View source

#sin(value : Float64)

Calculates the sine of value, measured in radians.

View source

#sin(value)

Calculates the sine of value, measured in radians.

View source

#sin(value : Float32)

Calculates the sine of value, measured in radians.

View source

#sinh(value : Float32)

Calculates the hyperbolic sine of value.

View source

#sinh(value : Float64)

Calculates the hyperbolic sine of value.

View source

#sinh(value)

Calculates the hyperbolic sine of value.

View source

#sqrt(value)

Calculates the square root of value.

View source

#sqrt(value : BigFloat)

Calculates the square root of value.

require "big"

Math.sqrt(1_000_000_000_000.to_big_f * 1_000_000_000_000.to_big_f) # => 1000000000000.0
View source

#sqrt(value : Float32)

Calculates the square root of value.

View source

#sqrt(value : Float64)

Calculates the square root of value.

View source

#sqrt(value : BigInt)

Calculates the square root of value.

require "big"

Math.sqrt(1_000_000_000_000.to_big_i * 1_000_000_000_000.to_big_i) # => 1000000000000.0
View source

#sqrt(value : BigRational)

Calculates the square root of value.

require "big"

Math.sqrt(1_000_000_000_000.to_big_r * 1_000_000_000_000.to_big_r) # => 1000000000000.0
View source

#sqrt(value : Complex)

Calculates the square root of value. Inspired by the following blog post of Pavel Panchekha on floating point precision.

require "complex"

Math.sqrt(4 + 2.i) # => 2.0581710272714924 + 0.48586827175664565i

Although the imaginary number is defined as i = sqrt(-1), calling Math.sqrt with a negative number will return -NaN. To obtain the result in the complex plane, Math.sqrt must be called with a complex number.

Math.sqrt(-1.0)         # => -NaN
Math.sqrt(-1.0 + 0.0.i) # => 0.0 + 1.0i
View source

#tan(value)

Calculates the tangent of value, measured in radians.

View source

#tan(value : Float64)

Calculates the tangent of value, measured in radians.

View source

#tan(value : Float32)

Calculates the tangent of value, measured in radians.

View source

#tanh(value : Float64)

Calculates the hyperbolic tangent of value.

View source

#tanh(value)

Calculates the hyperbolic tangent of value.

View source

#tanh(value : Float32)

Calculates the hyperbolic tangent of value.

View source