1 | import { factory } from '../../utils/factory'
|
2 | import { deepMap } from '../../utils/collection'
|
3 |
|
4 | const name = 'im'
|
5 | const dependencies = ['typed']
|
6 |
|
7 | export const createIm = /* #__PURE__ */ factory(name, dependencies, ({ typed }) => {
|
8 | /**
|
9 | * Get the imaginary part of a complex number.
|
10 | * For a complex number `a + bi`, the function returns `b`.
|
11 | *
|
12 | * For matrices, the function is evaluated element wise.
|
13 | *
|
14 | * Syntax:
|
15 | *
|
16 | * math.im(x)
|
17 | *
|
18 | * Examples:
|
19 | *
|
20 | * const a = math.complex(2, 3)
|
21 | * math.re(a) // returns number 2
|
22 | * math.im(a) // returns number 3
|
23 | *
|
24 | * math.re(math.complex('-5.2i')) // returns number -5.2
|
25 | * math.re(math.complex(2.4)) // returns number 0
|
26 | *
|
27 | * See also:
|
28 | *
|
29 | * re, conj, abs, arg
|
30 | *
|
31 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
32 | * A complex number or array with complex numbers
|
33 | * @return {number | BigNumber | Array | Matrix} The imaginary part of x
|
34 | */
|
35 | const im = typed(name, {
|
36 | number: function (x) {
|
37 | return 0
|
38 | },
|
39 |
|
40 | BigNumber: function (x) {
|
41 | return x.mul(0)
|
42 | },
|
43 |
|
44 | Complex: function (x) {
|
45 | return x.im
|
46 | },
|
47 |
|
48 | 'Array | Matrix': function (x) {
|
49 | return deepMap(x, im)
|
50 | }
|
51 | })
|
52 |
|
53 | return im
|
54 | })
|