1 |
|
2 |
|
3 | # Function sign
|
4 |
|
5 | Compute the sign of a value. The sign of a value x is:
|
6 |
|
7 | - 1 when x > 0
|
8 | - -1 when x < 0
|
9 | - 0 when x == 0
|
10 |
|
11 | For matrices, the function is evaluated element wise.
|
12 |
|
13 |
|
14 | ## Syntax
|
15 |
|
16 | ```js
|
17 | math.sign(x)
|
18 | ```
|
19 |
|
20 | ### Parameters
|
21 |
|
22 | Parameter | Type | Description
|
23 | --------- | ---- | -----------
|
24 | `x` | number | BigNumber | Fraction | Complex | Array | Matrix | Unit | The number for which to determine the sign
|
25 |
|
26 | ### Returns
|
27 |
|
28 | Type | Description
|
29 | ---- | -----------
|
30 | number | BigNumber | Fraction | Complex | Array | Matrix | Unit | e The sign of `x`
|
31 |
|
32 |
|
33 | ## Examples
|
34 |
|
35 | ```js
|
36 | math.sign(3.5) // returns 1
|
37 | math.sign(-4.2) // returns -1
|
38 | math.sign(0) // returns 0
|
39 |
|
40 | math.sign([3, 5, -2, 0, 2]) // returns [1, 1, -1, 0, 1]
|
41 | ```
|
42 |
|
43 |
|
44 | ## See also
|
45 |
|
46 | [abs](abs.md)
|
47 |
|
\ | No newline at end of file |