Predicator.Functions.MathFunctions (predicator v6.0.0)

Copy Markdown 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)",
...>   %{}, 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

function_result()

@type function_result() :: {:ok, Predicator.Types.value()} | {:error, binary()}

Functions

call_abs(list, context)

Returns the absolute value of a number.

call_ceil(list, context)

Rounds a number up to the nearest integer.

call_floor(list, context)

Rounds a number down to the nearest integer.

call_max(list, context)

Returns the larger of two numbers.

call_min(list, context)

Returns the smaller of two numbers.

call_pow(list, context)

Raises base to the power of exponent.

call_random(list, context)

Returns a random float between 0 and 1.

call_round(list, context)

Rounds a number to the nearest integer.

call_sqrt(list, context)

Returns the square root of a number.

functions()

@spec functions() :: %{
  required(Predicator.FunctionProvider.name()) =>
    Predicator.FunctionProvider.entry()
}

Returns all math functions as a Predicator.FunctionProvider map.