1 | import { factory } from '../../utils/factory'
|
2 | import { multiplyNumber } from '../../plain/number'
|
3 |
|
4 | const name = 'multiplyScalar'
|
5 | const dependencies = ['typed']
|
6 |
|
7 | export const createMultiplyScalar = factory(name, dependencies, ({ typed }) => {
|
8 | |
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | const multiplyScalar = typed('multiplyScalar', {
|
21 |
|
22 | 'number, number': multiplyNumber,
|
23 |
|
24 | 'Complex, Complex': function (x, y) {
|
25 | return x.mul(y)
|
26 | },
|
27 |
|
28 | 'BigNumber, BigNumber': function (x, y) {
|
29 | return x.times(y)
|
30 | },
|
31 |
|
32 | 'Fraction, Fraction': function (x, y) {
|
33 | return x.mul(y)
|
34 | },
|
35 |
|
36 | 'number | Fraction | BigNumber | Complex, Unit': function (x, y) {
|
37 | const res = y.clone()
|
38 | res.value = (res.value === null) ? res._normalize(x) : multiplyScalar(res.value, x)
|
39 | return res
|
40 | },
|
41 |
|
42 | 'Unit, number | Fraction | BigNumber | Complex': function (x, y) {
|
43 | const res = x.clone()
|
44 | res.value = (res.value === null) ? res._normalize(y) : multiplyScalar(res.value, y)
|
45 | return res
|
46 | },
|
47 |
|
48 | 'Unit, Unit': function (x, y) {
|
49 | return x.multiply(y)
|
50 | }
|
51 |
|
52 | })
|
53 |
|
54 | return multiplyScalar
|
55 | })
|