mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
992 B
992 B
Function square
Compute the square of a value, x * x.
For matrices, the function is evaluated element wise.
Syntax
math.square(x)
Parameters
| Parameter | Type | Description |
|---|---|---|
x |
Number | BigNumber | Boolean | Complex | Array | Matrix | null | Number for which to calculate the square |
Returns
| Type | Description |
|---|---|
| Number | BigNumber | Complex | Array | Matrix | Squared value |
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.square([1, 2, 3, 4]); // returns Array [1, 4, 9, 16]