gleam_stats/math

A module containing several different kinds of mathematical functions and constants.


Functions

pub fn acos(x: Float) -> Float
pub fn acosh(x: Float) -> Float
pub fn asin(x: Float) -> Float
pub fn atan(x: Float) -> Float
pub fn atan2(y: Float, x: Float) -> Float
pub fn atanh(x: Float) -> Float
pub fn beta(x: Float, y: Float) -> Float

The beta function over the real numbers.

The implemented beta function is evaluated through the use of the gamma function.

pub fn ceil(x: Float) -> Float
pub fn combination(n: Int, k: Int) -> Result(Int, String)

A combinatorial function for computing the number of a k-combinations of n elements. Also known as “n choose k” or the binomial coefficient.

The implementation uses the effecient iterative multiplicative formula for the computation.

Example:
 import gleeunit/should
 import gleam_stats/math

 pub fn example() {
   // Invalid input gives an error
   // Error on: n = -1 < 0 
   math.combination(-1, 1)
   |> should.be_error()
 
   // Valid input returns a result
   math.combination(4, 0)
   |> should.equal(Ok(1))
 
   math.combination(4, 4)
   |> should.equal(Ok(1))
 
   math.combination(4, 2)
   |> should.equal(Ok(6))
 }
pub fn cos(x: Float) -> Float
pub fn cosh(x: Float) -> Float
pub fn erf(x: Float) -> Float
pub fn exp(x: Float) -> Float
pub fn factorial(n: Int) -> Result(Int, String)

A combinatorial function for computing the total number of combinations of n elements.

Example:
 import gleeunit/should
 import gleam_stats/math

 pub fn example() {
   // Invalid input gives an error
   math.factorial(-1)
   |> should.be_error()
 
   // Valid input returns a result
   math.factorial(0)
   |> should.equal(Ok(1))
   math.factorial(1)
   |> should.equal(Ok(1))
   math.factorial(2)
   |> should.equal(Ok(2))
   math.factorial(3)
   |> should.equal(Ok(6))
   math.factorial(4)
   |> should.equal(Ok(24))
 }
pub fn floor(x: Float) -> Float
pub fn gamma(x: Float) -> Float
pub fn gammainc(a: Float, x: Float) -> Result(Float, String)

The lower incomplete gamma function over the real numbers.

The implemented incomplete gamma function is evaluated through a power series expansion.

pub fn log(x: Float) -> Float
pub fn log10(x: Float) -> Float
pub fn log2(x: Float) -> Float
pub fn permutation(n: Int, k: Int) -> Result(Int, String)

A combinatorial function for computing the number of k-permuations (without repetitions) of n elements.

Example:
 import gleeunit/should
 import gleam_stats/math

 pub fn example() {
   // Invalid input gives an error
   // Error on: n = -1 < 0 
   math.permutation(-1, 1)
   |> should.be_error()
 
   // Valid input returns a result
   math.permutation(4, 0)
   |> should.equal(Ok(1))
 
   math.permutation(4, 4)
   |> should.equal(Ok(1))
 
   math.permutation(4, 2)
   |> should.equal(Ok(12))
 }
pub fn pi() -> Float
pub fn pow(x: Float, y: Float) -> Float
pub fn round(x: Float, precision: Int) -> Float

The function rounds a floating point number to a specific decimal precision.

Example:
 import gleeunit/should
 import gleam_stats/math

 pub fn example() {
   math.round(0.4444, 2) |> should.equal(0.44)
   math.round(0.4445, 2) |> should.equal(0.44)
   math.round(0.4455, 2) |> should.equal(0.45)
   math.round(0.4555, 2) |> should.equal(0.46)
 }
pub fn sign(x: Float) -> Float
pub fn sin(x: Float) -> Float
pub fn sinh(x: Float) -> Float
pub fn tanh(x: Float) -> Float
pub fn tau() -> Float