1 | 'use strict'
|
2 |
|
3 | function factory (type, config, load, typed) {
|
4 | const numeric = load(require('../../type/numeric'))
|
5 | const getTypeOf = load(require('../../function/utils/typeof'))
|
6 |
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | const divideScalar = typed('divide', {
|
21 | 'number, number': function (x, y) {
|
22 | return x / y
|
23 | },
|
24 |
|
25 | 'Complex, Complex': function (x, y) {
|
26 | return x.div(y)
|
27 | },
|
28 |
|
29 | 'BigNumber, BigNumber': function (x, y) {
|
30 | return x.div(y)
|
31 | },
|
32 |
|
33 | 'Fraction, Fraction': function (x, y) {
|
34 | return x.div(y)
|
35 | },
|
36 |
|
37 | 'Unit, number | Fraction | BigNumber': function (x, y) {
|
38 | const res = x.clone()
|
39 |
|
40 | const one = numeric(1, getTypeOf(y))
|
41 | res.value = divideScalar(((res.value === null) ? res._normalize(one) : res.value), y)
|
42 | return res
|
43 | },
|
44 |
|
45 | 'number | Fraction | BigNumber, Unit': function (x, y) {
|
46 | let res = y.clone()
|
47 | res = res.pow(-1)
|
48 |
|
49 | const one = numeric(1, getTypeOf(x))
|
50 | res.value = divideScalar(x, ((y.value === null) ? y._normalize(one) : y.value))
|
51 | return res
|
52 | },
|
53 |
|
54 | 'Unit, Unit': function (x, y) {
|
55 | return x.divide(y)
|
56 | }
|
57 |
|
58 | })
|
59 |
|
60 | return divideScalar
|
61 | }
|
62 |
|
63 | exports.factory = factory
|