Operators Functions (11)

Overloaded arithmetic operators for mixed types

add
Add two values.
Syntax
x + y | add(x | y)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Complex | Unit | Array | MatrixFirst value to add
ynumber | BigNumber | bigint | Fraction | Complex | Unit | Array | MatrixSecond value to add
Returns
number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix — Sum of `x` and `y`
Examples
a = 2.1 + 3.6
a - 3.6
3 + 2i
3 cm + 2 inch
2.3" + "4
See Also
subtract
divide
Divide two values.
Syntax
x / y | divide(x | y)
Type Signatures
Array | Matrix, Array | Matrix, DenseMatrix, any, SparseMatrix, any, Array, any, any, Array | Matrix
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Complex | Unit | Array | MatrixNumerator
ynumber | BigNumber | bigint | Fraction | Complex | Array | MatrixDenominator
Returns
number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix — Quotient, `x / y`
Examples
a = 2 / 3
a * 3
4.5 / 2
3 + 4 / 2
(3 + 4) / 2
See Also
multiply
dotDivide
Divide two values element wise.
Syntax
x ./ y | dotDivide(x | y)
Parameters
NameTypeDescription
xnumber | BigNumber | Fraction | Complex | Unit | Array | MatrixNumerator
ynumber | BigNumber | Fraction | Complex | Unit | Array | MatrixDenominator
Returns
number | BigNumber | Fraction | Complex | Unit | Array | Matrix — Quotient, `x ./ y`
Examples
a = [1
2
3; 4
5
6
dotMultiply
Multiply two values element wise.
Syntax
x .* y | dotMultiply(x | y)
Parameters
NameTypeDescription
xnumber | BigNumber | Fraction | Complex | Unit | Array | MatrixLeft hand value
ynumber | BigNumber | Fraction | Complex | Unit | Array | MatrixRight hand value
Returns
number | BigNumber | Fraction | Complex | Unit | Array | Matrix — Multiplication of `x` and `y`
Examples
a = [1
2
3; 4
5
6
dotPow
Calculates the power of x to y element wise.
Syntax
x .^ y | dotPow(x | y)
Parameters
NameTypeDescription
xnumber | BigNumber | Complex | Unit | Array | MatrixThe base
ynumber | BigNumber | Complex | Unit | Array | MatrixThe exponent
Returns
number | BigNumber | Complex | Unit | Array | Matrix — The value of `x` to the power `y`
Examples
a = [1
2
3; 4
5
6
See Also
pow
mod
Calculates the modulus, the remainder of an integer division.
Syntax
x % y | x mod y | mod(x
Type Signatures
BigNumber, BigNumber, bigint, bigint, Fraction, Fraction
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Array | MatrixDividend
ynumber | BigNumber | bigint | Fraction | Array | MatrixDivisor
Returns
number | BigNumber | bigint | Fraction | Array | Matrix — Returns the remainder of `x` divided by `y`.
Examples
7 % 3
11 % 2
10 mod 4
isOdd(x) = x % 2
isOdd(2)
See Also
divide
multiply
multiply two values.
Syntax
x * y | multiply(x | y)
Type Signatures
Matrix, Matrix, SparseMatrix, any, DenseMatrix, any, any, SparseMatrix, any, DenseMatrix, Array, any
Parameters
NameTypeDescription
aMatrixDense Vector (N)
bMatrixDense Vector (N)
Returns
number — Scalar value
Examples
a = 2.1 * 3.4
a / 3.4
2 * 3 + 4
2 * (3 + 4)
3 * 2.1 km
See Also
divide
pow
Calculates the power of x to y, x^y.
Syntax
x ^ y | pow(x | y)
Type Signatures
Complex, Complex, BigNumber, BigNumber, Fraction, Fraction, Array, BigNumber, Matrix, BigNumber, Unit, number | BigNumber
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Complex | Unit | Array | MatrixThe base
ynumber | BigNumber | bigint | ComplexThe exponent
Returns
number | BigNumber | bigint | Complex | Array | Matrix — The value of `x` to the power `y`
Examples
2^3
2*2*2
1 + e ^ (pi * i)
pow([[1
2
subtract
subtract two values.
Syntax
x - y | subtract(x | y)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Complex | Unit | Array | MatrixInitial value
ynumber | BigNumber | bigint | Fraction | Complex | Unit | Array | MatrixValue to subtract from `x`
Returns
number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix — Subtraction of `x` and `y`
Examples
a = 5.3 - 2
a + 2
2/3 - 1/6
2 * 3 - 3
2.1 km - 500m
See Also
add
unaryMinus
Inverse the sign of a value. Converts booleans and strings to numbers.
Syntax
-x | unaryMinus(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Complex | Unit | Array | MatrixNumber to be inverted.
Returns
number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix — Returns the value with inverted sign.
Examples
-4.5
-(-5.6)
-"22
unaryPlus
Converts booleans and strings to numbers.
Syntax
+x | unaryPlus(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | string | Complex | Unit | Array | Matrix
Returns
number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix —
Examples
+true
+"2