abs
Compute the absolute value.
Parameters
Name Type Description
x number | BigNumber | bigint | Fraction | Complex | Array | Matrix | Unit
Returns
number | BigNumber | bigint | Fraction | Complex | Array | Matrix | Unit —
Examples
abs(3.5) abs(-4.2)
addScalar
Add two scalar values, `x + y`. This function is meant for internal use: it is used by the public function `add` This function does not support collections (Array or Matrix).
Type Signatures
Complex, Complex, BigNumber, BigNumber, bigint, bigint, Fraction, Fraction
Parameters
Name Type Description
x number | BigNumber | bigint | Fraction | Complex | Unit First value to add
y number | BigNumber | bigint | Fraction | Complex Second value to add
Returns
number | BigNumber | bigint | Fraction | Complex | Unit — Sum of `x` and `y`
cbrt
Compute the cubic root value. If x = y * y * y, then y is the cubic root of x. When `x` is a number or complex number, an optional second argument `allRoots` can be provided to return all three cubic roots. If not provided, the principal root is returned
Syntax
cbrt(x) | cbrt(x | allRoots)
Parameters
Name Type Description
x number | BigNumber | Complex | Unit
allRoots boolean Optional, false by default. Only applicable
Returns
number | BigNumber | Complex | Unit —
Examples
cbrt(64) cube(4) cbrt(-8) cbrt(2 + 3i) cbrt(8i)
ceil
Round a value towards plus infinity. If x is complex, both real and imaginary part are rounded towards plus infinity.
Syntax
ceil(x) | ceil(x | n)
Type Signatures
number, number, Complex, number, Complex, BigNumber, BigNumber, BigNumber, Fraction, number, Fraction, BigNumber
Parameters
Name Type Description
x number | BigNumber | Fraction | Complex | Unit | Array | Matrix Value to be rounded
valuelessUnit Unit A valueless unit
Returns
number | BigNumber | Fraction | Complex | Unit | Array | Matrix — Rounded value
Examples
ceil(3.2) ceil(3.8) ceil(-4.2) ceil(3.241cm cm)
cube
Compute the cube of a value. The cube of x is x * x * x.
Parameters
Name Type Description
x number | BigNumber | bigint | Fraction | Complex | Unit Number for which to calculate the cube
Returns
number | BigNumber | bigint | Fraction | Complex | Unit — Cube of x
Examples
cube(2) 2^3 2 * 2 * 2
divideScalar
Divide two scalar values, `x / y`. This function is meant for internal use: it is used by the public functions `divide` and `inv`. This function does not support collections (Array or Matrix).
Type Signatures
number, number, Complex, Complex, BigNumber, BigNumber, bigint, bigint, Fraction, Fraction
Parameters
Name Type Description
x number | BigNumber | bigint | Fraction | Complex | Unit Numerator
y number | BigNumber | bigint | Fraction | Complex Denominator
Returns
number | BigNumber | bigint | Fraction | Complex | Unit — Quotient, `x / y`
exp
Calculate the exponent of a value.
Parameters
Name Type Description
x number | BigNumber | Complex A number to exponentiate
Returns
number | BigNumber | Complex — Exponential of `x`
Examples
exp(1.3) e ^ 1.3 log(exp(1.3)) x = 2.4 (exp(i*x) == cos(x) + i*sin(x)) # Euler\'s formula
expm
Compute the matrix exponential, expm(A) = e^A.
Parameters
Name Type Description
x Matrix A square Matrix
Returns
Matrix — The exponential of x
expm1
Calculate the value of subtracting 1 from the exponential value.
Parameters
Name Type Description
x number | BigNumber | Complex The number to exponentiate
Returns
number | BigNumber | Complex — Exponential of `x`, minus one
Examples
expm1(2) pow(e 2) - 1 log(expm1(2) + 1)
fix
Round a value towards zero. If x is complex, both real and imaginary part are rounded towards zero.
Syntax
fix(x) | fix(x | n)
Type Signatures
number, number, Complex, number, Complex, BigNumber, BigNumber, number | BigNumber, Fraction, number | BigNumber
Parameters
Name Type Description
x number | BigNumber | Fraction | Complex | Unit | Array | Matrix Value to be rounded
valuelessUnit Unit A valueless unit
Returns
number | BigNumber | Fraction | Complex | Unit | Array | Matrix — Rounded value
Examples
fix(3.2) fix(3.8) fix(-4.2) fix(-4.8) fix(3.241cm
floor
Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.
Syntax
floor(x) | floor(x | n)
Type Signatures
number, number, Complex, number, Complex, BigNumber, BigNumber, BigNumber, Fraction, number, Fraction, BigNumber
Parameters
Name Type Description
x number | BigNumber | Fraction | Complex | Unit | Array | Matrix Value to be rounded
valuelessUnit Unit A valueless unit
Returns
number | BigNumber | Fraction | Complex | Unit | Array | Matrix — Rounded value
Examples
floor(3.2) floor(3.8) floor(-4.2) floor(3.241cm cm)
gcd
Compute the greatest common divisor.
Syntax
gcd(a | b) | gcd(a
Parameters
Name Type Description
args ... number | BigNumber | Fraction | Array | Matrix Two or more integer numbers
Returns
number | BigNumber | Fraction | Array | Matrix — The greatest common divisor
Examples
gcd(8 12) gcd(-4 6) gcd(25
hypot
Calculate the hypotenuse of a list with values.
Parameters
Name Type Description
args ... number | BigNumber | Array | Matrix A list with numeric values or an Array or Matrix.
Returns
number | BigNumber — Returns the hypothenusa of the input values.
Examples
hypot(3 4) sqrt(3^2 + 4^2) hypot(-2) hypot([3
invmod
Calculate the (modular) multiplicative inverse of a modulo b. Solution to the equation ax ≣ 1 (mod b)
Parameters
Name Type Description
a number | BigNumber An integer number
b number | BigNumber An integer number
Returns
number | BigNumber — Returns an integer number
Examples
invmod(8 12) invmod(7 13) invmod(15151
lcm
Compute the least common multiple.
Parameters
Name Type Description
args ... number | BigNumber | Array | Matrix Two or more integer numbers
Returns
number | BigNumber | Array | Matrix — The least common multiple
Examples
lcm(4 6) lcm(6 21) lcm(6
log
Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).
Syntax
log(x) | log(x | base)
Parameters
Name Type Description
x number | BigNumber | Fraction | Complex
Returns
number | BigNumber | Fraction | Complex —
Examples
log(3.5) a = log(2.4) exp(a) 10 ^ 4 log(10000
log10
Compute the 10-base logarithm of a value.
Parameters
Name Type Description
x number | BigNumber | Complex | Array | Matrix
Returns
number | BigNumber | Complex | Array | Matrix —
Examples
log10(0.00001) log10(10000) 10 ^ 4 log(10000) / log(10) log(10000
log1p
Calculate the logarithm of a `value+1`
Syntax
log1p(x) | log1p(x | base)
Parameters
Name Type Description
x number | BigNumber | Complex | Array | Matrix
Returns
number | BigNumber | Complex | Array | Matrix —
Examples
log1p(2.5) exp(log1p(1.4)) pow(10 4) log1p(9999
log2
Calculate the 2-base of a value. This is the same as calculating `log(x, 2)`.
Parameters
Name Type Description
x number | BigNumber | Complex | Array | Matrix
Returns
number | BigNumber | Complex | Array | Matrix —
Examples
log2(0.03125) log2(16) log2(16) / log2(2) pow(2 4)
multiplyScalar
Multiply two scalar values, `x * y`. This function is meant for internal use: it is used by the public function `multiply` This function does not support collections (Array or Matrix).
Type Signatures
Complex, Complex, BigNumber, BigNumber, bigint, bigint, Fraction, Fraction
Parameters
Name Type Description
x number | BigNumber | bigint | Fraction | Complex | Unit First value to multiply
y number | BigNumber | bigint | Fraction | Complex Second value to multiply
Returns
number | BigNumber | bigint | Fraction | Complex | Unit — Multiplication of `x` and `y`
norm
Calculate the norm of a number, vector or matrix.
Syntax
norm(x) | norm(x | p)
Type Signatures
Array, number | BigNumber | string, Matrix, number | BigNumber | string
Parameters
Name Type Description
x number | BigNumber | Complex | Array | Matrix
Returns
number | BigNumber — the p-norm
Examples
abs(-3.5) norm(-3.5) norm(3 - 4i) norm([1 2
nthRoot
Calculate the nth root of a value.
Syntax
nthRoot(a) | nthRoot(a | root)
Parameters
Name Type Description
a number | BigNumber | Array | Matrix | Complex
Returns
number | Complex | Array | Matrix — Returns the nth root of `a`
Examples
4 ^ 3 nthRoot(64 3) nthRoot(9 2)
nthRoots
Syntax
nthRoots(A) | nthRoots(A | root)
Parameters
Name Type Description
val number
Returns
Complex — val, i*val, -val or -i*val for index 0, 1, 2, 3
Examples
nthRoots(1) nthRoots(1 3)
round
round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.
Syntax
round(x) | round(x | n)
Type Signatures
number, number, number, BigNumber, Complex, number, Complex, BigNumber, BigNumber, BigNumber, Fraction, number
Parameters
Name Type Description
x number | BigNumber | Fraction | Complex | Unit | Array | Matrix Value to be rounded
valuelessUnit Unit A valueless unit
Returns
number | BigNumber | Fraction | Complex | Unit | Array | Matrix — Rounded value
Examples
round(3.2) round(3.8) round(-4.2) round(-4.8) round(pi
sign
Compute the sign of a value. The sign of a value x is 1 when x>0, -1 when x<0, and 0 when x=0.
Parameters
Name Type Description
x number | BigNumber | bigint | Fraction | Complex | Array | Matrix | Unit
Returns
number | BigNumber | bigint | Fraction | Complex | Array | Matrix | Unit —
Examples
sign(3.5) sign(-4.2) sign(0)
sqrt
Compute the square root value. If x = y * y, then y is the square root of x.
Parameters
Name Type Description
x number | BigNumber | Complex | Unit
Returns
number | BigNumber | Complex | Unit —
Examples
sqrt(25) 5 * 5 sqrt(-1)
sqrtm
Calculate the principal square root of a square matrix. The principal square root matrix `X` of another matrix `A` is such that `X * X = A`.
Type Signatures
Array | Matrix
Parameters
Name Type Description
A Array | Matrix The square matrix `A`
Returns
Array | Matrix — The principal square root of matrix `A`
square
Compute the square of a value. The square of x is x * x.
Parameters
Name Type Description
x number | BigNumber | bigint | Fraction | Complex | Unit
Returns
number | BigNumber | bigint | Fraction | Complex | Unit —
Examples
square(3) sqrt(9) 3^2 3 * 3
subtractScalar
Subtract two scalar values, `x - y`. This function is meant for internal use: it is used by the public function `subtract` This function does not support collections (Array or Matrix).
Type Signatures
Complex, Complex, BigNumber, BigNumber, bigint, bigint, Fraction, Fraction
Parameters
Name Type Description
x number | BigNumber | bigint | Fraction | Complex | Unit First value
y number | BigNumber | bigint | Fraction | Complex Second value to be subtracted from `x`
Returns
number | BigNumber | bigint | Fraction | Complex | Unit — Difference of `x` and `y`
xgcd
Calculate the extended greatest common divisor for two values. The result is an array [d, x, y] with 3 entries, where d is the greatest common divisor, and d = x * a + y * b.
Type Signatures
number, number
Parameters
Name Type Description
a number | BigNumber An integer number
b number | BigNumber An integer number
Returns
Array — Returns an array containing 3 integers `[div, m, n]`
Examples
xgcd(8 12) gcd(8 12) xgcd(36163