Function square #
Compute the square of a value, x * x
.
To avoid confusion with multiplying a square matrix by itself,
this function does not apply to matrices. If you wish to square
every element of a matrix, see the examples.
Syntax #
math.square(x)
Parameters #
Parameter | Type | Description |
---|---|---|
x |
number | BigNumber | bigint | Fraction | Complex | Unit | Number for which to calculate the square |
Returns #
Type | Description |
---|---|
number | BigNumber | bigint | Fraction | Complex | Unit | Squared value |
Throws #
Type | Description —- | ———–
Examples #
math.square(2) // returns number 4
math.square(3) // returns number 9
math.pow(3, 2) // returns number 9
math.multiply(3, 3) // returns number 9
math.map([1, 2, 3, 4], math.square) // returns Array [1, 4, 9, 16]