# Math functions

The following list contains the functions that you can use to perform mathematical calculations.

## abs()#

Returns the absolute value of a `number`.

``abs(number)``

#### Arguments#

`number` (Number)
The number to convert.

#### Returns#

(Number)
The absolute value of the `number`.

#### Examples#

InputExpressionResult
``-5``
``abs(@)``
``5``

``add(augend, addend)``

#### Arguments#

`augend` (Number)
The first number in an addition.
`addend` (Number)
The second number in an addition.

#### Returns#

(Number)
The resulted sum of two numbers.

#### Examples#

InputExpressionResult
``""``
``add(1, 2)``
``3``
``[1, 2]``
``add(, )``
``3``

## avg()#

Computes the average of the values in the `array`.

Aliases: `mean()`.

``avg(array)``

#### Arguments#

`array` (Array | Null)
The array to iterate over.

(Number)
The average.

#### Examples#

InputExpressionResult
``[4, 2, 8, 6]``
``avg(@)``
``5``

## avg_by()#

This method is like avg() except that it accepts `iteratee` which is invoked for each element in `array` to generate the value to be averaged.

Aliases: `mean_by()`

``avg_by(array, [iteratee])``

#### Arguments#

`array` (Array | Null)
The array to iterate over.
`iteratee` (Expression | Array | Object | String)
(Optional) The iteratee invoked per element of the `array`. Default value is `&@`

(Number)
The average.

#### Examples#

InputExpressionResult
``[    {        "name": "Mike",        "age": 40    },    {        "name": "Ben",        "age": 35    },    {        "name": "Fred",        "age": 30    }]``
``````avg_by(@, &age)
``````
``35``

## ceil()#

Computes `number` rounded up to `precision`.

``ceil(number, [precision])``

#### Arguments#

`number` (Number)
The number to round up.
`precision` (Number)
(Optional) The precision to round up to. Default value is `0`.

#### Returns#

(Number)
The rounded up number.

#### Examples#

InputExpressionResult
``3.14159``
``ceil(@)``
``4``
``3.14159``
``ceil(@, 2)``
``3.15``
``5001``
``ceil(@, -2)``
``5100``

## divide()#

Divide two numbers.

``divide(dividend, divisor)``

#### Arguments#

`dividend` (Number)
The first number in a division.
`divisor` (Number)
The second number in a division.

(Number)
The quotient.

#### Examples#

InputExpressionResult
``[]``
``divide(4, 2)``
``2``
``[10, 5]``
``divide(, )``
``2``
``{    "quantity": 3,    "amount": 45.3}``
``divide(amount, quantity)``
``15.1``

## floor()#

Computes `number` rounded down to `precision`.

``floor(number, [precision])``

#### Arguments#

`number` (Number)
The number to round down.
`precision` (Number)
(Optional) The precision to round down to. Default value is `0`.

#### Returns#

(Number)
The rounded down number.

#### Examples#

InputExpressionResult
``3.14159``
``floor(@)``
``3``
``3.14159``
``floor(@, 2)``
``3.14``
``5010``
``floor(@, -2)``
``5000``

## inverse()#

Returns the `number` with the opposite sign.

``inverse(number)``

#### Arguments#

`number` (Number)
The number to inverse.

#### Returns#

(Number)
The inversed number.

#### Examples#

InputExpressionResult
``3``
``inverse(@)``
``-3``

## math_const_e()#

Returns Euler's number, the base of natural logarithms, e, which is approximately `2.718`.

``math_const_e()``

(Number)
The e number

#### Examples#

InputExpressionResult
``[]``
``math_const_e()``
``2.718281828459045``

## math_const_ln10()#

Returns the natural logarithm of 10, approximately `2.302`.

``math_const_ln10()``

#### Returns#

(Number)
The natural logarithm of 10 number.

#### Examples#

InputExpressionResult
``[]``
``math_const_ln10()``
``2.302585092994046``

## math_const_ln2()#

Returns the natural logarithm of 2, approximately `0.693`.

``math_const_ln2()``

#### Returns#

(Number)
The natural logarithm of 2 number.

#### Examples#

InputExpressionResult
``[]``
``math_const_ln2()``
``0.6931471805599453``

## math_const_log10e()#

Returns the base 10 logarithm of e, approximately `0.434`.

``math_const_log10e()``

#### Returns#

(Number)
The base 10 logarithm of e number.

#### Examples#

InputExpressionResult
``[]``
``math_const_log10e()``
``0.4342944819032518``

## math_const_log2e()#

Returns the base 2 logarithm of e, approximately `1.442`.

``math_const_log2e()``

#### Returns#

(Number)
The base 2 logarithm of e number.

#### Examples#

InputExpressionResult
``[]``
``math_const_log2e()``
``1.4426950408889634``

## math_const_pi()#

Returns the ratio of the circumference of a circle to its diameter, the Pi number, approximately `3.14159`.

``math_const_pi()``

(Number)
The Pi number.

#### Examples#

InputExpressionResult
``[]``
``math_const_pi()``
``3.141592653589793``

## math_const_sqrt1_2()#

Returns the square root of 1/2 which is approximately `0.707`.

``math_const_sqrt1_2()``

#### Returns#

(Number)
The square root of 1/2 number.

#### Examples#

InputExpressionResult
``[]``
``math_const_sqrt1_2()``
``0.7071067811865476``

## math_const_sqrt2()#

Returns the square root of 2, approximately `1.414`.

``math_const_sqrt2()``

#### Returns#

(Number)
The square root of 2 number.

#### Examples#

InputExpressionResult
``[]``
``math_const_sqrt2()``
``1.4142135623730951``

## max()#

Computes the maximum value of `array`. If `array` is empty or falsey, undefined is returned.

``max(array)``

#### Arguments#

`array` (Array)
The array to iterate over.

#### Returns#

(Any)
The maximum value.

#### Examples#

InputExpressionResult
``[4, 2, 8, 5]``
``max(@)``
``8``
``["a", "b", "c"]``
``max(@)``
``"c"``

## max_by()#

This method is like max() except that it accepts `iteratee` which is invoked for each element in `array` to generate the criterion by which the value is ranked. The `iteratee` is invoked with one argument: (`value`).

``max_by(array, [iteratee])``

#### Arguments#

`array` (Array | Null)
The array to iterate over.
`iteratee` (Expression | Array | Object | String)
(Optional) The iteratee invoked per element of the `array`. Default value is `&@`

#### Returns#

(Any)
The maximum value.

#### Examples#

InputExpressionResult
``[1.2, 3.5, 2.2]``
``max_by(@, &floor(@))``
``3.5``
``[    {        "name": "Mike",        "age": 40    },    {        "name": "Ben",        "age": 35    },    {        "name": "Fred",        "age": 20    }]``
``max_by(@, &age)``
``{    "name": "Mike",    "age": 40}``

Alias for avg().

## mean_by()#

Alias for avg_by().

## min()#

Computes the minimum value of `array`. If `array` is empty or falsey, undefined is returned.

``min(array)``

#### Arguments#

`array` (Array)
The array to iterate over.

#### Returns#

(Any)
The minimum value.

#### Examples#

InputExpressionResult
``[4, 2, 8, 5]``
``min(@)``
``2``
``["a", "b", "c"]``
``min(@)``
``"a"``

## min_by()#

This method is like min() except that it accepts `iteratee` which is invoked for each element in `array` to generate the criterion by which the value is ranked. The `iteratee` is invoked with one argument: (`value`).

``min_by(array, [iteratee])``

#### Arguments#

`array` (Array | Null)
The array to iterate over.
`iteratee` (Expression | Array | Object | String)
(Optional) The iteratee invoked per element of the `array`. Default value is `&@`

#### Returns#

(Any)
The minimum value.

#### Examples#

InputExpressionResult
``[1.2, 3.5, 1.19]``
``min_by(@, &floor(@))``
``1.2``
``[    {        "name": "Mike",        "age": 40    },    {        "name": "Ben",        "age": 35    },    {        "name": "Fred",        "age": 20    }]``
``min_by(@, &age)``
``{    "name": "Fred",    "age": 20}``

## multiply()#

Multiply two numbers.

``multiply(multiplier, multiplicand)``

#### Arguments#

`multiplier` (Number)
The first number in a multiplication.
`multiplicand` (Number)
The second number in a multiplication.

(Number)
The product.

#### Examples#

InputExpressionResult
``[]``
``multiply(2, 3)``
``6``
``[10, 5]``
``multiply(, )``
``50``

## round()#

Computes `number` rounded to `precision`.

``round(number, [precision])``

#### Arguments#

`number` (Number)
The number to round.
`precision` (Number)
(Optional) The precision to round to. Default value is `0`.

#### Returns#

(Number)
The rounded number.

#### Examples#

InputExpressionResult
``3.14159``
``round(@)``
``3``
``3.14159``
``round(@, 2)``
``3.14``
``5010``
``round(@, -2)``
``5000``

## sign()#

Returns the sign of the `number`.

``sign(number)``

#### Arguments#

`number` (Number)
The number to inspect.

#### Returns#

(Number)
`1` if number is positive, else `-1`.

#### Examples#

InputExpressionResult
``3``
``sign(@)``
``1``
``-3``
``sign(@)``
``-1``

## subtract()#

Subtract two numbers.

``subtract(minuend, subtrahend)``

#### Arguments#

`minuend` (Number)
The first number in a subtraction.
`subtrahend` (Number)
The second number in a subtraction.

(Number)
The difference.

#### Examples#

InputExpressionResult
``[]``
``subtract(3, 2)``
``1``
``[5, 3]``
``subtract(, )``
``2``

## sum()#

Computes the sum of the values in `array`.

``sum(array)``

#### Arguments#

`array` (Array)
The array to iterate over.

(Number)
The sum.

#### Examples#

InputExpressionResult
``[4, 2, 8, 6]``
``sum(@)``
``20``

## sum_by()#

This method is like sum() except that it accepts `iteratee` which is invoked for each element in array to generate the criterion by which the value is ranked. The `iteratee` is invoked with one argument: (`value`).

``sum_by(array, [iteratee])``

#### Arguments#

`array` (Array | Null)
The array to iterate over.
`iteratee` (Expression | Array | Object | String)
(Optional) The iteratee invoked per element of the `array`. Default value is `&@`

(Number)
The sum.

#### Examples#

InputExpressionResult
``[1.2, 3.5, 2.2]``
``sum_by(@, &floor(@))``
``6``
``[    {        "name": "Mike",        "age": 40    },    {        "name": "Ben",        "age": 35    },    {        "name": "Fred",        "age": 20    }]``
``sum_by(@, &age)``
``95``

• abs()
• avg()
• avg_by()
• ceil()
• divide()
• floor()
• inverse()
• math_const_e()
• math_const_ln10()
• math_const_ln2()
• math_const_log10e()
• math_const_log2e()
• math_const_pi()
• math_const_sqrt1_2()
• math_const_sqrt2()
• max()
• max_by()
• mean()
• mean_by()
• min()
• min_by()
• multiply()
• round()
• sign()
• subtract()
• sum()
• sum_by()