Predicator.Functions.MathFunctions (predicator v3.5.0)
View SourceMathematical functions for Predicator expressions.
Provides SCXML-compatible Math functions for numerical computations.
Available Functions
Math.pow(base, exponent)- Raises base to the power of exponentMath.sqrt(value)- Returns the square root of a numberMath.abs(value)- Returns the absolute valueMath.floor(value)- Rounds down to the nearest integerMath.ceil(value)- Rounds up to the nearest integerMath.round(value)- Rounds to the nearest integerMath.min(a, b)- Returns the smaller of two numbersMath.max(a, b)- Returns the larger of two numbersMath.random()- Returns a random float between 0 and 1
Examples
iex> {:ok, result} = Predicator.evaluate("Math.pow(2, 3)",
...> %{}, functions: Predicator.Functions.MathFunctions.all_functions())
iex> result
8.0
iex> {:ok, result} = Predicator.evaluate("Math.sqrt(16)",
...> %{}, functions: Predicator.Functions.MathFunctions.all_functions())
iex> result
4.0
Summary
Functions
@spec all_functions() :: %{required(binary()) => {non_neg_integer(), function()}}