mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
945 B
945 B
Function sign
Compute the sign of a value. The sign of a value x is:
- 1 when x > 1
- -1 when x < 0
- 0 when x == 0
For matrices, the function is evaluated element wise.
Syntax
math.sign(x)
Parameters
| Parameter | Type | Description |
|---|---|---|
x |
Number | BigNumber | Boolean | Complex | Array | Matrix | null | The number for which to determine the sign |
Returns
| Type | Description |
|---|---|
| Number | BigNumber | Complex | Array | Matrix | e The sign of x |
Examples
math.sign(3.5); // returns 1
math.sign(-4.2); // returns -1
math.sign(0); // returns 0
math.sign([3, 5, -2, 0, 2]); // returns [1, 1, -1, 0, 1]