UNPKG

1.55 kBJavaScriptView Raw
1'use strict'
2
3function factory (type, config, load, typed) {
4 /**
5 * Multiply two scalar values, `x * y`.
6 * This function is meant for internal use: it is used by the public function
7 * `multiply`
8 *
9 * This function does not support collections (Array or Matrix), and does
10 * not validate the number of of inputs.
11 *
12 * @param {number | BigNumber | Fraction | Complex | Unit} x First value to multiply
13 * @param {number | BigNumber | Fraction | Complex} y Second value to multiply
14 * @return {number | BigNumber | Fraction | Complex | Unit} Multiplication of `x` and `y`
15 * @private
16 */
17 const multiplyScalar = typed('multiplyScalar', {
18
19 'number, number': function (x, y) {
20 return x * y
21 },
22
23 'Complex, Complex': function (x, y) {
24 return x.mul(y)
25 },
26
27 'BigNumber, BigNumber': function (x, y) {
28 return x.times(y)
29 },
30
31 'Fraction, Fraction': function (x, y) {
32 return x.mul(y)
33 },
34
35 'number | Fraction | BigNumber | Complex, Unit': function (x, y) {
36 const res = y.clone()
37 res.value = (res.value === null) ? res._normalize(x) : multiplyScalar(res.value, x)
38 return res
39 },
40
41 'Unit, number | Fraction | BigNumber | Complex': function (x, y) {
42 const res = x.clone()
43 res.value = (res.value === null) ? res._normalize(y) : multiplyScalar(res.value, y)
44 return res
45 },
46
47 'Unit, Unit': function (x, y) {
48 return x.multiply(y)
49 }
50
51 })
52
53 return multiplyScalar
54}
55
56exports.factory = factory