Skip to main content

Math functions

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

acos()​

Returns the arccosine (in radians) of a number.

acos(x)

Arguments​

x (Number)
A number representing a cosine, where x is between -1 and 1.

Returns​

(Number)
The arccosine (angle in radians) of the given number if it's between -1 and 1; otherwise, NaN.

Examples​

InputExpressionResult
0
acos(@)
1.5707963267948966

See also​


acosh()​

Returns the hyperbolic arc-cosine of a number.

acosh(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The hyperbolic arc-cosine of the given number. If the number is less than 1, NaN.

Examples​

InputExpressionResult
1
acosh(@)
0

See also​


add()​

Adds two numbers.

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([0], [1])
3

See also​


asin()​

Returns the arcsine (in radians) of a number.

asin(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The arcsine (in radians) of the given number if it's between -1 and 1; otherwise, NaN.

Examples​

InputExpressionResult
0.5
asin(@)
0.5235987755982989

See also​


asinh()​

Returns the hyperbolic arcsine of a number.

asinh(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The hyperbolic arcsine of the given number.

Examples​

InputExpressionResult
1
asinh(@)
0.881373587019543

See also​


atan()​

Returns the arctangent (in radians) of a number.

atan(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The arctangent (in radians) of the given number.

Examples​

InputExpressionResult
1
atan(@)
0.7853981633974483

See also​


atan2()​

Returns the angle in the plane (in radians) between the positive x-axis and the ray from (0,0) to the point (x,y).

atan2(y, x)

Arguments​

y (Number)
The y coordinate of the point.
x (Number)
The x coordinate of the point.

Returns​

(Number)
The angle in radians between the positive x-axis and the ray from (0,0) to the point (x,y).

Examples​

InputExpressionResult
[90, 15]
atan2([0], [1])
1.4056476493802699

atanh()​

Returns the hyperbolic arctangent of a number.

atanh(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The hyperbolic arctangent of the given number.

Examples​

InputExpressionResult
0.5
atanh(@)
0.5493061443340548

See also​


avg()​

Computes the average of the values in the array.

Aliases: mean().

avg(array)

Arguments​

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

Returns​

(Number)
The average.

Examples​

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

See also​


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 &@

Returns​

(Number)
The average.

Examples​

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

35

See also​


cbrt()​

Returns the cubic root of a number.

cbrt(number)

Arguments​

number (Number)
A number.

Returns​

(Number)
The cube root of the given number.

Examples​

InputExpressionResult
64
cbrt(@)
4

See also​


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

See also​


cos()​

Returns the cosine of the specified angle, which must be specified in radians.

cos(x)

Arguments​

x (Number)
The angle in radians for which to return the cosine.

Returns​

(Number)
The cosine of the given number.

Examples​

InputExpressionResult
1
cos(@)
0.5403023058681398

See also​


cosh()​

Returns the hyperbolic cosine of a number.

cosh(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The hyperbolic cosine of the given number.

Examples​

InputExpressionResult
1
cosh(@)
1.5430806348152437

See also​


exp()​

Returns e^x, where x is the argument, and e is the base of natural logarithms.

exp(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The value of e to the power x.

Examples​

InputExpressionResult
-1
exp(@)
0.36787944117144233

See also​


expm1()​

Returns e^x - 1, where x is the argument, and e is the base of natural logarithms.

expm1(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
A number representing e^x - 1.

Examples​

InputExpressionResult
-1
expm1(@)
-0.6321205588285577

See also​


div()​

Same as divide().


divide()​

Divide two numbers.

Aliases: div()

divide(dividend, divisor)

Arguments​

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

Returns​

(Number)
The quotient.

Examples​

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

See also​


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

See also​


hypot()​

Returns the square root of the sum of squares of array elements.

hypot(array)

Arguments​

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

Returns​

(Number)
The square root of the sum of squares of the given array elements.

Examples​

InputExpressionResult
[3, 4]
hypot(@)
5
null
hypot(@)
0

See also​


ln()​

Returns the natural logarithm (base e) of a number.

ln(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The natural logarithm of the given number. NaN if the number is negative. -Infinity if the number is 0.

Examples​

InputExpressionResult
10
ln(@)
2.302585092994046

See also​


log()​

Returns the base base logarithm of x.

log(x, [base])

Arguments​

x (Number)
A number.
base (Number)
(Optional) A number. Default value is 10.

Returns​

(Number)
The base base logarithm of the given number. NaN if the number is negative. -Infinity if the number is 0.

Examples​

InputExpressionResult
[8, 2]
log([0], [1])
3

See also​


log10()​

Returns the base 10 logarithm of a number.

log10(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The base 10 logarithm of the given number. If the number is negative, NaN is returned.

Examples​

InputExpressionResult
2
log10(@)
0.3010299956639812

See also​


log2()​

Returns the base 2 logarithm of a number.

log2(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The base 2 logarithm of the given number.

Examples​

InputExpressionResult
3
log2(@)
1.584962500721156

See also​


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

See also​


math_e()​

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

math_e()

Returns​

(Number)
The e number

Examples​

InputExpressionResult
[]
math_e()
2.718281828459045

math_ln10()​

Returns the natural logarithm of 10, approximately 2.302.

math_ln10()

Returns​

(Number)
The natural logarithm of 10 number.

Examples​

InputExpressionResult
[]
math_ln10()
2.302585092994046

math_ln2()​

Returns the natural logarithm of 2, approximately 0.693.

math_ln2()

Returns​

(Number)
The natural logarithm of 2 number.

Examples​

InputExpressionResult
[]
math_ln2()
0.6931471805599453

math_log10e()​

Returns the base 10 logarithm of e, approximately 0.434.

math_log10e()

Returns​

(Number)
The base 10 logarithm of e number.

Examples​

InputExpressionResult
[]
math_log10e()
0.4342944819032518

math_log2e()​

Returns the base 2 logarithm of e, approximately 1.442.

math_log2e()

Returns​

(Number)
The base 2 logarithm of e number.

Examples​

InputExpressionResult
[]
math_log2e()
1.4426950408889634

math_pi()​

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

math_pi()

Returns​

(Number)
The Pi number.

Examples​

InputExpressionResult
[]
math_pi()
3.141592653589793

math_sqrt1_2()​

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

math_sqrt1_2()

Returns​

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

Examples​

InputExpressionResult
[]
math_sqrt1_2()
0.7071067811865476

math_sqrt2()​

Returns the square root of 2, approximately 1.414.

math_sqrt2()

Returns​

(Number)
The square root of 2 number.

Examples​

InputExpressionResult
[]
math_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"

See also​


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: @ (current element).

max_by(array, [iteratee])

Arguments​

array (Array | Null)
The array to iterate over.
iteratee (Expression | Array | Object | String)
(Optional) The expression invoked per iteration. The iteratee expression is invoked with one argument: @ (current element). 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
}

See also​


mean()​

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"

See also​


mod()​

Same as modulo().


modulo()​

Returns the remainder left over when a dividend is divided by a divisor. It always takes the sign of the dividend.

Aliases: mod()

mod(dividend, divisor)

Arguments​

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

Returns​

(Number)
The remainder of dividing two numbers. If one of the operands is NaN, or if divisor is 0, returns NaN.

Examples​

InputExpressionResult
[13, 5]
modulo([0], [1])
3
[-13, 5]
modulo([0], [1])
-3

See also​


pow()​

Returns the value of base to the power of exponent.

pow(base, exponent)

Arguments​

base (Number)
The base.
exponent (Number)
The exponent.

Returns​

(Number)
A number representing the value of base to the power of exponent.

Examples​

InputExpressionResult
[7, 2]
pow([0], [1])
49

See also​


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: @ (current element).

min_by(array, [iteratee])

Arguments​

array (Array | Null)
The array to iterate over.
iteratee (Expression | Array | Object | String)
(Optional) The expression invoked per iteration. The iteratee expression is invoked with one argument: @ (current element). 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
}

See also​


mul()​

Same as multiply().


multiply()​

Multiply two numbers.

Aliases: mul()

multiply(multiplier, multiplicand)

Arguments​

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

Returns​

(Number)
The product.

Examples​

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

See also​


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

See also​


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

sin()​

Returns the sine of a number.

sin(x)

Arguments​

x (Number)
The angle in radians for which to return the sine.

Returns​

(Number)
The sine of the given number.

Examples​

InputExpressionResult
1
sin(@)
0.8414709848078965

See also​


sinh()​

Returns the hyperbolic sine of a number.

sinh(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The hyperbolic sine of the given number.

Examples​

InputExpressionResult
1
sinh(@)
1.1752011936438014

See also​


sqrt()​

Returns the square root of a number.

sqrt(number)

Arguments​

number (Number)
A number.

Returns​

(Number)
The square root of the given number. If the number is negative, NaN is returned.

Examples​

InputExpressionResult
4
sqrt(@)
2

See also​


sub()​

Same as subtract().


subtract()​

Subtract two numbers.

Aliases: sub()

subtract(minuend, subtrahend)

Arguments​

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

Returns​

(Number)
The difference.

Examples​

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

See also​


sum()​

Computes the sum of the values in array.

sum(array)

Arguments​

array (Array)
The array to iterate over.

Returns​

(Number)
The sum.

Examples​

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

See also​


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: @ (current element).

sum_by(array, [iteratee])

Arguments​

array (Array | Null)
The array to iterate over.
iteratee (Expression | Array | Object | String)
(Optional) The expression invoked per iteration. The iteratee expression is invoked with one argument: @ (current element). Default value is &@.

Returns​

(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

See also​


tan()​

Returns the tangent of a number.

tan(x)

Arguments​

x (Number)
A number representing an angle in radians.

Returns​

(Number)
The tangent of the given number.

Examples​

InputExpressionResult
1
tan(@)
1.5574077246549023

See also​


tanh()​

Returns the hyperbolic tangent of a number.

tanh(x)

Arguments​

x (Number)
A number.

Returns​

(Number)
The hyperbolic tangent of the given number.

Examples​

InputExpressionResult
1
tanh(@)
0.7615941559557649

See also​


trunc()​

Returns the integer part of a number by removing any fractional digits.

trunc(number)

Arguments​

x (Number)
A number.

Returns​

(Number)
The integer part of the given number.

Examples​

InputExpressionResult
42.4242
trunc(@)
42

See also​