# `Predicator.Functions.MathFunctions`
[🔗](https://github.com/riddler/predicator-ex/blob/v9.5.0/lib/predicator/functions/math_functions.ex#L1)

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; integer
  in, non-negative integer exponent, integer out
- `Math.sqrt(value)` - Returns the square root of a number; integer in with
  an exact integer root, integer out
- `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

    iex> {:ok, result} = Predicator.evaluate("Math.sqrt(16)",
    ...>   %{}, providers: [Predicator.Functions.MathFunctions])
    iex> result
    4

# `function_result`

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

# `call_abs`

```elixir
@spec call_abs([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Returns the absolute value of a number.

# `call_ceil`

```elixir
@spec call_ceil([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Rounds a number up to the nearest integer.

# `call_floor`

```elixir
@spec call_floor([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Rounds a number down to the nearest integer.

# `call_max`

```elixir
@spec call_max([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Returns the larger of two numbers.

# `call_min`

```elixir
@spec call_min([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Returns the smaller of two numbers.

# `call_pow`

```elixir
@spec call_pow([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Raises base to the power of exponent.

Returns an integer when both arguments are integers and the exponent is
non-negative - computed exactly, with no float rounding at large magnitudes.
Returns a float otherwise (float argument, or negative exponent).

# `call_random`

```elixir
@spec call_random([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Returns a random float between 0 and 1.

# `call_round`

```elixir
@spec call_round([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Rounds a number to the nearest integer.

# `call_sqrt`

```elixir
@spec call_sqrt([Predicator.Types.value()], Predicator.Context.t()) ::
  function_result()
```

Returns the square root of a number.

Returns an integer when the argument is a non-negative integer with an exact
integer square root (`Math.sqrt(16)` is `4`). Returns a float otherwise. A
negative argument is an error, not NaN.

# `functions`

```elixir
@spec functions() :: %{
  required(Predicator.FunctionProvider.name()) =&gt;
    Predicator.FunctionProvider.entry()
}
```

Returns all math functions as a `Predicator.FunctionProvider` map.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
