Predicator.Functions.MathFunctions (predicator v3.5.0)

View Source

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 exponent
  • Math.sqrt(value) - Returns the square root of a number
  • Math.abs(value) - Returns the absolute value
  • Math.floor(value) - Rounds down to the nearest integer
  • Math.ceil(value) - Rounds up to the nearest integer
  • Math.round(value) - Rounds to the nearest integer
  • Math.min(a, b) - Returns the smaller of two numbers
  • Math.max(a, b) - Returns the larger of two numbers
  • Math.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

all_functions()

@spec all_functions() :: %{required(binary()) => {non_neg_integer(), function()}}