1 | 'use strict'
|
2 |
|
3 | function factory (type, config, load, typed) {
|
4 | |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | const add = typed('add', {
|
18 |
|
19 | 'number, number': function (x, y) {
|
20 | return x + y
|
21 | },
|
22 |
|
23 | 'Complex, Complex': function (x, y) {
|
24 | return x.add(y)
|
25 | },
|
26 |
|
27 | 'BigNumber, BigNumber': function (x, y) {
|
28 | return x.plus(y)
|
29 | },
|
30 |
|
31 | 'Fraction, Fraction': function (x, y) {
|
32 | return x.add(y)
|
33 | },
|
34 |
|
35 | 'Unit, Unit': function (x, y) {
|
36 | if (x.value === null || x.value === undefined) throw new Error('Parameter x contains a unit with undefined value')
|
37 | if (y.value === null || y.value === undefined) throw new Error('Parameter y contains a unit with undefined value')
|
38 | if (!x.equalBase(y)) throw new Error('Units do not match')
|
39 |
|
40 | const res = x.clone()
|
41 | res.value = add(res.value, y.value)
|
42 | res.fixPrefix = false
|
43 | return res
|
44 | }
|
45 | })
|
46 |
|
47 | return add
|
48 | }
|
49 |
|
50 | exports.factory = factory
|