53 lines
1021 B
Markdown
53 lines
1021 B
Markdown
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|
||
|
|
||
|
# Function sign
|
||
|
|
||
|
Compute the sign of a value. The sign of a value x is:
|
||
|
|
||
|
- 1 when x > 0
|
||
|
- -1 when x < 0
|
||
|
- 0 when x == 0
|
||
|
|
||
|
For matrices, the function is evaluated element wise.
|
||
|
|
||
|
|
||
|
## Syntax
|
||
|
|
||
|
```js
|
||
|
math.sign(x)
|
||
|
```
|
||
|
|
||
|
### Parameters
|
||
|
|
||
|
Parameter | Type | Description
|
||
|
--------- | ---- | -----------
|
||
|
`x` | number | BigNumber | Fraction | Complex | Array | Matrix | Unit | The number for which to determine the sign
|
||
|
|
||
|
### Returns
|
||
|
|
||
|
Type | Description
|
||
|
---- | -----------
|
||
|
number | BigNumber | Fraction | Complex | Array | Matrix | Unit | e The sign of `x`
|
||
|
|
||
|
|
||
|
### Throws
|
||
|
|
||
|
Type | Description
|
||
|
---- | -----------
|
||
|
|
||
|
|
||
|
## Examples
|
||
|
|
||
|
```js
|
||
|
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]
|
||
|
```
|
||
|
|
||
|
|
||
|
## See also
|
||
|
|
||
|
[abs](abs.md)
|