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 asinh(value: Float) -> Float

Returns the inverse hyperbolic sine of a number.

pub fn atan(value: Float) -> Float

Returns the arctangent of a number, in radians.

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 cbrt(value: Float) -> Float

Returns the cube root of a number.

pub fn clz32(value: Int) -> Int

Returns the number of leading zero bits in the 32-bit integer representation of a number.

pub fn cos(angle: Float) -> Float

Returns the cosine of an angle in radians.

pub fn cosh(value: Float) -> Float

Returns the hyperbolic cosine of a number.

pub const e: Float

Euler’s number, the base of natural logarithms.

pub fn exp(value: Float) -> Float

Returns e raised to the power 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 const ln10: Float

The natural logarithm of 10.

pub const ln2: Float

The natural logarithm of 2.

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 const log10e: Float

The base-10 logarithm of e.

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 const log2e: Float

The base-2 logarithm of e.

pub const pi: Float

The ratio of a circle’s circumference to its diameter.

pub fn random() -> Float

Returns a pseudo-random floating-point number between 0 (inclusive) and 1 (exclusive).

pub fn sign(value: Float) -> Float

Returns the sign of a number: -1.0, 0.0, or 1.0.

pub fn sin(angle: Float) -> Float

Returns the sine of an angle in radians.

pub fn sinh(value: Float) -> Float

Returns the hyperbolic sine of a number.

pub const sqrt1_2: Float

The square root of 1/2.

pub const sqrt2: Float

The square root of 2.

pub fn tan(angle: Float) -> Float

Returns the tangent of an angle in radians.

pub fn tanh(value: Float) -> Float

Returns the hyperbolic tangent of a number.

pub fn trunc(value: Float) -> Float

Returns the integer part of a number by removing any fractional digits, rounding toward zero.

Search Document