> For the complete documentation index, see [llms.txt](https://machinations.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://machinations.gitbook.io/docs/registers/math.js-functions.md).

# Math.js Functions

All Math.js functions supported

## Arithmetic functions

| Function                                                                        | What it does                                                                                                         |
| ------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [abs(x)](https://mathjs.org/docs/reference/functions/abs.html)                  | Calculate the absolute value of a number                                                                             |
| [add(x, y)](https://mathjs.org/docs/reference/functions/add.html)               | Add two or more values, x + y                                                                                        |
| [cbrt(x \[, allRoots\])](https://mathjs.org/docs/reference/functions/cbrt.html) | Calculates the cubic root of a value                                                                                 |
| [ceil(x)](https://mathjs.org/docs/reference/functions/ceil.html)                | Round a value towards plus infinity If x is complex, both real and imaginary parts are rounded towards plus infinity |
| [cube(x)](https://mathjs.org/docs/reference/functions/cube.html)                | Compute the cube of a value, x \* x \* x                                                                             |
| [divide(x, y)](https://mathjs.org/docs/reference/functions/divide.html)         | Divide two values, x / y                                                                                             |
| [dotPow(x, y)](https://mathjs.org/docs/reference/functions/dotPow.html)         | Calculates the power of x to y element-wise                                                                          |
| [exp(x)](https://mathjs.org/docs/reference/functions/exp.html)                  | Calculate the exponent of a value                                                                                    |
| [expm1(x)](https://mathjs.org/docs/reference/functions/expm1.html)              | Calculate the value of subtracting 1 from the exponential value                                                      |
| [fix(x)](https://mathjs.org/docs/reference/functions/fix.html)                  | Round a value towards zero                                                                                           |
| [floor(x)](https://mathjs.org/docs/reference/functions/floor.html)              | Round a value towards minus infinity                                                                                 |
| [gcd(a, b)](https://mathjs.org/docs/reference/functions/gcd.html)               | Calculate the greatest common divisor for two or more values or arrays                                               |
| [hypot(a, b, …)](https://mathjs.org/docs/reference/functions/hypot.html)        | Calculate the hypotenusa of a list with values                                                                       |
| [lcm(a, b)](https://mathjs.org/docs/reference/functions/lcm.html)               | Calculate the least common multiple for two or more values or arrays                                                 |
| [log(x \[, base\])](https://mathjs.org/docs/reference/functions/log.html)       | Calculate the logarithm of a value                                                                                   |
| [log10(x)](https://mathjs.org/docs/reference/functions/log10.html)              | Calculate the 10-base logarithm of a value                                                                           |
| [log1p(x)](https://mathjs.org/docs/reference/functions/log1p.html)              | Calculate the logarithm of a value+1                                                                                 |
| [log2(x)](https://mathjs.org/docs/reference/functions/log2.html)                | Calculate the 2-base of a value                                                                                      |
| [mod(x, y)](https://mathjs.org/docs/reference/functions/mod.html)               | Calculates the modulus, the remainder of an integer division                                                         |
| [multiply(x, y)](https://mathjs.org/docs/reference/functions/multiply.html)     | Multiply two or more values, x \* y                                                                                  |
| [norm(x \[, p\])](https://mathjs.org/docs/reference/functions/norm.html)        | Calculate the norm of a number, vector or matrix                                                                     |
| [nthRoot(a)](https://mathjs.org/docs/reference/functions/nthRoot.html)          | Calculate the nth root of a value                                                                                    |
| [nthRoots(x)](https://mathjs.org/docs/reference/functions/nthRoots.html)        | Calculate the nth roots of a value                                                                                   |
| [pow(x, y)](https://mathjs.org/docs/reference/functions/pow.html)               | Calculates the power of x to y, x ^ y                                                                                |
| [round(x \[, n\])](https://mathjs.org/docs/reference/functions/round.html)      | Round a value towards the nearest integer                                                                            |
| [sign(x)](https://mathjs.org/docs/reference/functions/sign.html)                | Compute the sign of a value                                                                                          |
| [sqrt(x)](https://mathjs.org/docs/reference/functions/sqrt.html)                | Calculate the square root of a value                                                                                 |
| [square(x)](https://mathjs.org/docs/reference/functions/square.html)            | Compute the square of a value, x \* x                                                                                |
| [subtract(x, y)](https://mathjs.org/docs/reference/functions/subtract.html)     | Subtract two values, x - y                                                                                           |
| [unaryMinus(x)](https://mathjs.org/docs/reference/functions/unaryMinus.html)    | Inverse the sign of a value, apply a unary minus operation                                                           |
| [unaryPlus(x)](https://mathjs.org/docs/reference/functions/unaryPlus.html)      | Unary plus operation                                                                                                 |
| [xgcd(a, b)](https://mathjs.org/docs/reference/functions/xgcd.html)             | Calculate the extended greatest common divisor for two values                                                        |

## Bitwise Functions

| Functions                                                                                 | What it does                                                            |
| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [bitAnd(x, y)](https://mathjs.org/docs/reference/functions/bitAnd.html)                   | Bitwise AND two values, x & y                                           |
| [bitNot(x)](https://mathjs.org/docs/reference/functions/bitNot.html)                      | Bitwise NOT value, \~x                                                  |
| [bitOr(x, y)](https://mathjs.org/docs/reference/functions/bitOr.html)                     | Bitwise OR two values, x \| y                                           |
| [bitXor(x, y)](https://mathjs.org/docs/reference/functions/bitXor.html)                   | Bitwise XOR two values, x ^ y                                           |
| [leftShift(x, y)](https://mathjs.org/docs/reference/functions/leftShift.html)             | Bitwise left logical shift of a value x by y number of bits, x << y     |
| [rightArithShift(x, y)](https://mathjs.org/docs/reference/functions/rightArithShift.html) | Bitwise right arithmetic shift of a value x by y number of bits, x >> y |
| [rightLogShift(x, y)](https://mathjs.org/docs/reference/functions/rightLogShift.html)     | Bitwise right logical shift of value x by y number of bits, x >>> y     |

## Logical Functions

| Function                                                          | What it does |
| ----------------------------------------------------------------- | ------------ |
| [and(x, y)](https://mathjs.org/docs/reference/functions/and.html) | Logical and  |
| [not(x)](https://mathjs.org/docs/reference/functions/not.html)    | Logical not  |
| [or(x, y)](https://mathjs.org/docs/reference/functions/or.html)   | Logical or   |
| [xor(x, y)](https://mathjs.org/docs/reference/functions/xor.html) | Logical xor  |

## Matrix Functions

| Function                                                         | What it does                             |
| ---------------------------------------------------------------- | ---------------------------------------- |
| [size(x)](https://mathjs.org/docs/reference/functions/size.html) | Calculate the size of a matrix or scalar |
| [sort(x)](https://mathjs.org/docs/reference/functions/sort.html) | Sort the items in a matrix               |

## Probability Functions

| Function                                                                              | What it does                                                                                                                                |
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| [factorial(n)](https://mathjs.org/docs/reference/functions/factorial.html)            | Compute the factorial of a value Factorial only supports an integer value as argument                                                       |
| [gamma(n)](https://mathjs.org/docs/reference/functions/gamma.html)                    | Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values |
| [pickRandom(array)](https://mathjs.org/docs/reference/functions/pickRandom.html)      | Random pick one or more values from a one dimensional array                                                                                 |
| [random(\[min, max\])](https://mathjs.org/docs/reference/functions/random.html)       | Return a random number larger or equal to min and smaller than max using a uniform distribution                                             |
| [randomInt(\[min, max\])](https://mathjs.org/docs/reference/functions/randomInt.html) | Return a random integer number larger or equal to min and smaller than max using a uniform distribution                                     |

## Relational Functions

| Function                                                                                | Whate it does                                                  |
| --------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [compare(x, y)](https://mathjs.org/docs/reference/functions/compare.html)               | Compare two values                                             |
| [compareNatural(x, y)](https://mathjs.org/docs/reference/functions/compareNatural.html) | Compare two values of any type in a deterministic, natural way |
| [equal(x, y)](https://mathjs.org/docs/reference/functions/equal.html)                   | Test whether two values are equal                              |
| [larger(x, y)](https://mathjs.org/docs/reference/functions/larger.html)                 | Test whether value x is larger than y                          |
| [largerEq(x, y)](https://mathjs.org/docs/reference/functions/largerEq.html)             | Test whether value x is larger or equal to y                   |
| [smaller(x, y)](https://mathjs.org/docs/reference/functions/smaller.html)               | Test whether value x is smaller than y                         |
| [smallerEq(x, y)](https://mathjs.org/docs/reference/functions/smallerEq.html)           | Test whether value x is smaller or equal to y                  |
| [unequal(x, y)](https://mathjs.org/docs/reference/functions/unequal.html)               | Test whether two values are unequal                            |

## Statistics Functions

| Function                                                                          | What it does                                                                       |
| --------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [mad(a, b, c, …)](https://mathjs.org/docs/reference/functions/mad.html)           | Compute the median absolute deviation of a matrix or a list with values            |
| [max(a, b, c, …)](https://mathjs.org/docs/reference/functions/max.html)           | Compute the maximum value of a matrix or a list with values                        |
| [mean(a, b, c, …)](https://mathjs.org/docs/reference/functions/mean.html)         | Compute the mean value of matrix or a list with values                             |
| [median(a, b, c, …)](https://mathjs.org/docs/reference/functions/median.html)     | Compute the median of a matrix or a list with values                               |
| [min(a, b, c, …)](https://mathjs.org/docs/reference/functions/min.html)           | Compute the minimum value of a matrix or a list of values                          |
| [mode(a, b, c, …)](https://mathjs.org/docs/reference/functions/mode.html)         | Computes the mode of a set of numbers or a list with values(numbers or characters) |
| [prod(a, b, c, …)](https://mathjs.org/docs/reference/functions/prod.html)         | Compute the product of a matrix or a list with values                              |
| [std(a, b, c, …)](https://mathjs.org/docs/reference/functions/std.html)           | Compute the standard deviation of a matrix or a list with values                   |
| [sum(a, b, c, …)](https://mathjs.org/docs/reference/functions/sum.html)           | Compute the sum of a matrix or a list with values                                  |
| [variance(a, b, c, …)](https://mathjs.org/docs/reference/functions/variance.html) | Compute the variance of a matrix or a list with values                             |

## Trigonometry Functions

| Function                                                              | What it does                                                                                                         |
| --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [acos(x)](https://mathjs.org/docs/reference/functions/acos.html)      | Calculate the inverse cosine of a value                                                                              |
| [acosh(x)](https://mathjs.org/docs/reference/functions/acosh.html)    | Calculate the hyperbolic arccos of a value, defined as acosh(x) = ln(sqrt(x^2 - 1) + x)                              |
| [acot(x)](https://mathjs.org/docs/reference/functions/acot.html)      | Calculate the inverse cotangent of a value, defined as acot(x) = atan(1/x)                                           |
| [acoth(x)](https://mathjs.org/docs/reference/functions/acoth.html)    | Calculate the hyperbolic arccotangent of a value, defined as acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2 |
| [acsc(x)](https://mathjs.org/docs/reference/functions/acsc.html)      | Calculate the inverse cosecant of a value, defined as acsc(x) = asin(1/x)                                            |
| [acsch(x)](https://mathjs.org/docs/reference/functions/acsch.html)    | Calculate the hyperbolic arccosecant of a value, defined as acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1))        |
| [asec(x)](https://mathjs.org/docs/reference/functions/asec.html)      | Calculate the inverse secant of a value                                                                              |
| [asech(x)](https://mathjs.org/docs/reference/functions/asech.html)    | Calculate the hyperbolic arcsecant of a value, defined as asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x)          |
| [asin(x)](https://mathjs.org/docs/reference/functions/asin.html)      | Calculate the inverse sine of a value                                                                                |
| [asinh(x)](https://mathjs.org/docs/reference/functions/asinh.html)    | Calculate the hyperbolic arcsine of a value, defined as asinh(x) = ln(x + sqrt(x^2 + 1))                             |
| [atan(x)](https://mathjs.org/docs/reference/functions/atan.html)      | Calculate the inverse tangent of a value                                                                             |
| [atan2(y, x)](https://mathjs.org/docs/reference/functions/atan2.html) | Calculate the inverse tangent function with two arguments, y/x                                                       |
| [atanh(x)](https://mathjs.org/docs/reference/functions/atanh.html)    | Calculate the hyperbolic arctangent of a value, defined as atanh(x) = ln((1 + x)/(1 - x)) / 2                        |
| [cos(x)](https://mathjs.org/docs/reference/functions/cos.html)        | Calculate the cosine of a value                                                                                      |
| [cosh(x)](https://mathjs.org/docs/reference/functions/cosh.html)      | Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 \* (exp(x) + exp(-x))                           |
| [cot(x)](https://mathjs.org/docs/reference/functions/cot.html)        | Calculate the cotangent of a value                                                                                   |
| [coth(x)](https://mathjs.org/docs/reference/functions/coth.html)      | Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 / tanh(x)                                      |
| [csc(x)](https://mathjs.org/docs/reference/functions/csc.html)        | Calculate the cosecant of a value, defined as csc(x) = 1/sin(x)                                                      |
| [csch(x)](https://mathjs.org/docs/reference/functions/csch.html)      | Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 / sinh(x)                                       |
| [sec(x)](https://mathjs.org/docs/reference/functions/sec.html)        | Calculate the secant of a value, defined as sec(x) = 1/cos(x)                                                        |
| [sech(x)](https://mathjs.org/docs/reference/functions/sech.html)      | Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / cosh(x)                                         |
| [sin(x)](https://mathjs.org/docs/reference/functions/sin.html)        | Calculate the sine of a value                                                                                        |
| [sinh(x)](https://mathjs.org/docs/reference/functions/sinh.html)      | Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 \* (exp(x) - exp(-x))                             |
| [tan(x)](https://mathjs.org/docs/reference/functions/tan.html)        | Calculate the tangent of a value                                                                                     |
| [tanh(x)](https://mathjs.org/docs/reference/functions/tanh.html)      | Calculate the hyperbolic tangent of a value, defined as tanh(x)=(exp(2 \* x) - 1)/(exp(2 \* x)+1)                    |

## Utils Functions

| Function                                                                               | What it does                                                             |
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [hasNumericValue(x)](https://mathjs.org/docs/reference/functions/hasNumericValue.html) | Test whether a value is a numeric value                                  |
| [isInteger(x)](https://mathjs.org/docs/reference/functions/isInteger.html)             | Test whether a value is an integer number                                |
| [isNaN(x)](https://mathjs.org/docs/reference/functions/isNaN.html)                     | Test whether a value is NaN (not a number)                               |
| [isNegative(x)](https://mathjs.org/docs/reference/functions/isNegative.html)           | Test whether a value is negative: smaller than zero                      |
| [isNumeric(x)](https://mathjs.org/docs/reference/functions/isNumeric.html)             | Test whether a value is an numeric value                                 |
| [isPositive(x)](https://mathjs.org/docs/reference/functions/isPositive.html)           | Test whether a value is positive: larger than zero                       |
| [isPrime(x)](https://mathjs.org/docs/reference/functions/isPrime.html)                 | Test whether a value is prime: has no divisors other than itself and one |
| [isZero(x)](https://mathjs.org/docs/reference/functions/isZero.html)                   | Test whether a value is zero                                             |
