1 |
|
2 |
|
3 | # Function abs
|
4 |
|
5 | Calculate the absolute value of a number. For matrices, the function is
|
6 | evaluated element wise.
|
7 |
|
8 |
|
9 | ## Syntax
|
10 |
|
11 | ```js
|
12 | math.abs(x)
|
13 | ```
|
14 |
|
15 | ### Parameters
|
16 |
|
17 | Parameter | Type | Description
|
18 | --------- | ---- | -----------
|
19 | `x` | number | BigNumber | Fraction | Complex | Array | Matrix | Unit | A number or matrix for which to get the absolute value
|
20 |
|
21 | ### Returns
|
22 |
|
23 | Type | Description
|
24 | ---- | -----------
|
25 | number | BigNumber | Fraction | Complex | Array | Matrix | Unit | Absolute value of `x`
|
26 |
|
27 |
|
28 | ## Examples
|
29 |
|
30 | ```js
|
31 | math.abs(3.5) // returns number 3.5
|
32 | math.abs(-4.2) // returns number 4.2
|
33 |
|
34 | math.abs([3, -5, -1, 0, 2]) // returns Array [3, 5, 1, 0, 2]
|
35 | ```
|
36 |
|
37 |
|
38 | ## See also
|
39 |
|
40 | [sign](sign.md)
|