gcalc/alg

A set of algebraic operations for Gleam programs

Types

MathError represents an error that can occur when performing a mathematical operation

pub type MathError {
  DivisionByZero
  ValueOutOfRange
  UnsupportedOperation
}

Constructors

  • DivisionByZero
  • ValueOutOfRange
  • UnsupportedOperation

Functions

pub fn abs(n: Float) -> Float

Returns the absolute value of the argument

pub fn factorial(n: Float) -> Result(Float, MathError)

Returns a result containing the factorial of the argument or an error if the argument is negative

Note: This function only supports non-negative values

pub fn pow(base: Float, power: Float) -> Float

Returns the exponentiation of the two arguments (i.e. the first argument raised to the power of the second argument)

pub fn sqrt(n: Float) -> Result(Float, MathError)

Returns a result containing the square root of the argument or an error if the argument is negative

Note: This function only supports non-negative values and returns the floor of the result (i.e. the largest integer less than or equal to the result)

Search Document