module Math
¶
Extended modules
Math
Constants¶
E = LibM.exp_f64(1.0)
¶
LibM.exp_f64(1.0)
Euler's number (e).
LOG10 = LibM.log_f64(10.0)
¶
LibM.log_f64(10.0)
LOG2 = LibM.log_f64(2.0)
¶
LibM.log_f64(2.0)
PI = 3.14159265358979323846
¶
3.14159265358979323846
Archimedes' constant (Ï€).
TAU = 6.283185307179586476925
¶
6.283185307179586476925
The full circle constant (Ï„), equal to 2Ï€.
Methods¶
#atan2(y, x)
¶
(y, x)
Calculates the two-argument arc tangent of the ray from (0, 0) to (x, y).
#atan2(y : Float32, x : Float32)
¶
(y : Float32, x : Float32)
Calculates the two-argument arc tangent of the ray from (0, 0) to (x, y).
#atan2(y : Float64, x : Float64)
¶
(y : Float64, x : Float64)
Calculates the two-argument arc tangent of the ray from (0, 0) to (x, y).
#besselj(order : Int32, value : Float32)
¶
(order : Int32, value : Float32)
Calculates the cylindrical Bessel function of the first kind of value for the given order.
#besselj(order, value)
¶
(order, value)
Calculates the cylindrical Bessel function of the first kind of value for the given order.
#besselj(order : Int32, value : Float64)
¶
(order : Int32, value : Float64)
Calculates the cylindrical Bessel function of the first kind of value for the given order.
#besselj0(value : Float64)
¶
(value : Float64)
Calculates the cylindrical Bessel function of the first kind of value for order 0.
#besselj0(value)
¶
(value)
Calculates the cylindrical Bessel function of the first kind of value for order 0.
#besselj0(value : Float32)
¶
(value : Float32)
Calculates the cylindrical Bessel function of the first kind of value for order 0.
#besselj1(value)
¶
(value)
Calculates the cylindrical Bessel function of the first kind of value for order 1.
#besselj1(value : Float64)
¶
(value : Float64)
Calculates the cylindrical Bessel function of the first kind of value for order 1.
#besselj1(value : Float32)
¶
(value : Float32)
Calculates the cylindrical Bessel function of the first kind of value for order 1.
#bessely(order, value)
¶
(order, value)
Calculates the cylindrical Bessel function of the second kind of value for the given order.
#bessely(order : Int32, value : Float64)
¶
(order : Int32, value : Float64)
Calculates the cylindrical Bessel function of the second kind of value for the given order.
#bessely(order : Int32, value : Float32)
¶
(order : Int32, value : Float32)
Calculates the cylindrical Bessel function of the second kind of value for the given order.
#bessely0(value : Float32)
¶
(value : Float32)
Calculates the cylindrical Bessel function of the second kind of value for order 0.
#bessely0(value : Float64)
¶
(value : Float64)
Calculates the cylindrical Bessel function of the second kind of value for order 0.
#bessely0(value)
¶
(value)
Calculates the cylindrical Bessel function of the second kind of value for order 0.
#bessely1(value : Float32)
¶
(value : Float32)
Calculates the cylindrical Bessel function of the second kind of value for order 1.
#bessely1(value)
¶
(value)
Calculates the cylindrical Bessel function of the second kind of value for order 1.
#bessely1(value : Float64)
¶
(value : Float64)
Calculates the cylindrical Bessel function of the second kind of value for order 1.
#copysign(value1 : Float32, value2 : Float32)
¶
(value1 : Float32, value2 : Float32)
Returns the floating-point value with the magnitude of value1 and the sign of value2.
#copysign(value1 : Float64, value2 : Float64)
¶
(value1 : Float64, value2 : Float64)
Returns the floating-point value with the magnitude of value1 and the sign of value2.
#copysign(value1, value2)
¶
(value1, value2)
Returns the floating-point value with the magnitude of value1 and the sign of value2.
#exp(value : Complex)
¶
(value : Complex)
Calculates the exponential of value.
require "complex"
Math.exp(4 + 2.i) # => -22.720847417619233 + 49.645957334580565i
#frexp(value)
¶
(value)
Decomposes the given floating-point value into a normalized fraction and an integral power of two.
#frexp(value : Float32)
¶
(value : Float32)
Decomposes the given floating-point value into a normalized fraction and an integral power of two.
#frexp(value : Float64)
¶
(value : Float64)
Decomposes the given floating-point value into a normalized fraction and an integral power of two.
#frexp(value : BigFloat)
¶
(value : BigFloat)
Decomposes the given floating-point value into a normalized fraction and an integral power of two.
#gamma(value)
¶
(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.
#gamma(value : Float64)
¶
(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.
#gamma(value : Float32)
¶
(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.
#hypot(value1 : Float64, value2 : Float64)
¶
(value1 : Float64, value2 : Float64)
Calculates the length of the hypotenuse from (0, 0) to (value1, value2).
Equivalent to
Math.sqrt(value1 ** 2 + value2 ** 2)
#hypot(value1 : Float32, value2 : Float32)
¶
(value1 : Float32, value2 : Float32)
Calculates the length of the hypotenuse from (0, 0) to (value1, value2).
Equivalent to
Math.sqrt(value1 ** 2 + value2 ** 2)
#hypot(value1, value2)
¶
(value1, value2)
Calculates the length of the hypotenuse from (0, 0) to (value1, value2).
Equivalent to
Math.sqrt(value1 ** 2 + value2 ** 2)
#ilogb(value : Float32)
¶
(value : Float32)
Returns the unbiased base 2 exponent of the given floating-point value.
#ilogb(value : Float64)
¶
(value : Float64)
Returns the unbiased base 2 exponent of the given floating-point value.
#ldexp(value, exp)
¶
(value, exp)
Multiplies the given floating-point value by 2 raised to the power exp.
#ldexp(value : Float32, exp : Int32)
¶
(value : Float32, exp : Int32)
Multiplies the given floating-point value by 2 raised to the power exp.
#ldexp(value : Float64, exp : Int32)
¶
(value : Float64, exp : Int32)
Multiplies the given floating-point value by 2 raised to the power exp.
#lgamma(value : Float32)
¶
(value : Float32)
Calculates the logarithmic gamma of value.
Math.lgamma(2.96)
Math.log(Math.gamma(2.96).abs)
#lgamma(value : Float64)
¶
(value : Float64)
Calculates the logarithmic gamma of value.
Math.lgamma(2.96)
Math.log(Math.gamma(2.96).abs)
#lgamma(value)
¶
(value)
Calculates the logarithmic gamma of value.
Math.lgamma(2.96)
Math.log(Math.gamma(2.96).abs)
#log(value : Complex)
¶
(value : Complex)
Calculates the natural logarithm of value.
require "complex"
Math.log(4 + 2.i) # => 1.4978661367769956 + 0.4636476090008061i
#log10(value : Complex)
¶
(value : Complex)
Calculates the logarithm of value to base 10.
require "complex"
Math.log10(4 + 2.i) # => 0.6505149978319906 + 0.20135959813668655i
#log2(value : Complex)
¶
(value : Complex)
Calculates the logarithm of value to base 2.
require "complex"
Math.log2(4 + 2.i) # => 2.1609640474436813 + 0.6689021062254881i
#logb(value : Float32)
¶
(value : Float32)
Returns the unbiased radix-independent exponent of the given floating-point value.
#logb(value : Float64)
¶
(value : Float64)
Returns the unbiased radix-independent exponent of the given floating-point value.
#logb(value)
¶
(value)
Returns the unbiased radix-independent exponent of the given floating-point value.
#scalbln(value : Float32, exp : Int64)
¶
(value : Float32, exp : Int64)
Returns the floating-point value with its exponent raised by exp.
#scalbln(value : Float64, exp : Int64)
¶
(value : Float64, exp : Int64)
Returns the floating-point value with its exponent raised by exp.
#scalbln(value, exp)
¶
(value, exp)
Returns the floating-point value with its exponent raised by exp.
#scalbn(value : Float64, exp : Int32)
¶
(value : Float64, exp : Int32)
Returns the floating-point value with its exponent raised by exp.
#scalbn(value : Float32, exp : Int32)
¶
(value : Float32, exp : Int32)
Returns the floating-point value with its exponent raised by exp.
#sqrt(value : BigFloat)
¶
(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
#sqrt(value : BigInt)
¶
(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
#sqrt(value : BigRational)
¶
(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
#sqrt(value : Complex)
¶
(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