Mathematical 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)",
...> %{}, providers: [Predicator.Functions.MathFunctions])
iex> result
8.0
iex> {:ok, result} = Predicator.evaluate("Math.sqrt(16)",
...> %{}, providers: [Predicator.Functions.MathFunctions])
iex> result
4.0
Summary
Functions
Returns the absolute value of a number.
Rounds a number up to the nearest integer.
Rounds a number down to the nearest integer.
Returns the larger of two numbers.
Returns the smaller of two numbers.
Raises base to the power of exponent.
Returns a random float between 0 and 1.
Rounds a number to the nearest integer.
Returns the square root of a number.
Returns all math functions as a Predicator.FunctionProvider map.
Types
@type function_result() :: {:ok, Predicator.Types.value()} | {:error, binary()}
Functions
@spec call_abs([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Returns the absolute value of a number.
@spec call_ceil([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Rounds a number up to the nearest integer.
@spec call_floor([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Rounds a number down to the nearest integer.
@spec call_max([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Returns the larger of two numbers.
@spec call_min([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Returns the smaller of two numbers.
@spec call_pow([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Raises base to the power of exponent.
@spec call_random([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Returns a random float between 0 and 1.
@spec call_round([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Rounds a number to the nearest integer.
@spec call_sqrt([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Returns the square root of a number.
@spec functions() :: %{ required(Predicator.FunctionProvider.name()) => Predicator.FunctionProvider.entry() }
Returns all math functions as a Predicator.FunctionProvider map.