1 |
|
2 |
|
3 | # Function log2
|
4 |
|
5 | Calculate the 2-base of a value. This is the same as calculating `log(x, 2)`.
|
6 |
|
7 | For matrices, the function is evaluated element wise.
|
8 |
|
9 |
|
10 | ## Syntax
|
11 |
|
12 | ```js
|
13 | math.log2(x)
|
14 | ```
|
15 |
|
16 | ### Parameters
|
17 |
|
18 | Parameter | Type | Description
|
19 | --------- | ---- | -----------
|
20 | `x` | number | BigNumber | Complex | Array | Matrix | Value for which to calculate the logarithm.
|
21 |
|
22 | ### Returns
|
23 |
|
24 | Type | Description
|
25 | ---- | -----------
|
26 | number | BigNumber | Complex | Array | Matrix | Returns the 2-base logarithm of `x`
|
27 |
|
28 |
|
29 | ## Examples
|
30 |
|
31 | ```js
|
32 | math.log2(0.03125) // returns -5
|
33 | math.log2(16) // returns 4
|
34 | math.log2(16) / math.log2(2) // returns 4
|
35 | math.pow(2, 4) // returns 16
|
36 | ```
|
37 |
|
38 |
|
39 | ## See also
|
40 |
|
41 | [exp](exp.md),
|
42 | [log](log.md),
|
43 | [log1p](log1p.md),
|
44 | [log10](log10.md)
|