gossamer/math
Mathematical constants and functions mirroring JavaScript’s Math
object — trig, logs, exponentials, random, and more.
Values
pub fn acos(value: Float) -> Result(Float, Nil)
Returns the arccosine of a number, in radians. Returns an error if the
value is outside the range -1 to 1.
pub fn acosh(value: Float) -> Result(Float, Nil)
Returns the inverse hyperbolic cosine of a number. Returns an error if
the value is less than 1.
pub fn asin(value: Float) -> Result(Float, Nil)
Returns the arcsine of a number, in radians. Returns an error if the
value is outside the range -1 to 1.
pub fn atan2(y: Float, x: Float) -> Float
Returns the angle in radians between the positive x-axis and the point (x, y), with the result in the range -pi to pi.
pub fn atanh(value: Float) -> Result(Float, Nil)
Returns the inverse hyperbolic tangent of a number. Returns an error if
the absolute value is greater than or equal to 1.
pub fn clz32(value: Int) -> Int
Returns the number of leading zero bits in the 32-bit integer representation of a number.
pub fn expm1(value: Float) -> Float
Returns e raised to the power of a number minus 1, precise for small
values.
pub fn fround(value: Float) -> Float
Returns the nearest 32-bit single precision float representation of a number.
pub fn hypot(x: Float, y: Float) -> Float
Returns the square root of the sum of the squares of its arguments (the hypotenuse).
pub fn imul(a: Int, b: Int) -> Int
Returns the result of the C-like 32-bit integer multiplication of two numbers.
pub fn log(value: Float) -> Result(Float, Nil)
Returns the natural logarithm (base e) of a number. Returns an error if the value is not positive.
pub fn log10(value: Float) -> Result(Float, Nil)
Returns the base-10 logarithm of a number. Returns an error if the value is not positive.
pub fn log1p(value: Float) -> Result(Float, Nil)
Returns the natural logarithm of 1 + x, precise for small values of x.
Returns an error if x is less than or equal to -1.
pub fn log2(value: Float) -> Result(Float, Nil)
Returns the base-2 logarithm of a number. Returns an error if the value is not positive.
pub fn random() -> Float
Returns a pseudo-random floating-point number between 0 (inclusive) and
1 (exclusive).