UNPKG

1.58 kBJavaScriptView Raw
1import { factory } from '../../utils/factory.js';
2import { addNumber } from '../../plain/number/index.js';
3var name = 'addScalar';
4var dependencies = ['typed'];
5export var createAddScalar = /* #__PURE__ */factory(name, dependencies, (_ref) => {
6 var {
7 typed
8 } = _ref;
9
10 /**
11 * Add two scalar values, `x + y`.
12 * This function is meant for internal use: it is used by the public function
13 * `add`
14 *
15 * This function does not support collections (Array or Matrix).
16 *
17 * @param {number | BigNumber | Fraction | Complex | Unit} x First value to add
18 * @param {number | BigNumber | Fraction | Complex} y Second value to add
19 * @return {number | BigNumber | Fraction | Complex | Unit} Sum of `x` and `y`
20 * @private
21 */
22 return typed(name, {
23 'number, number': addNumber,
24 'Complex, Complex': function ComplexComplex(x, y) {
25 return x.add(y);
26 },
27 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
28 return x.plus(y);
29 },
30 'Fraction, Fraction': function FractionFraction(x, y) {
31 return x.add(y);
32 },
33 'Unit, Unit': function UnitUnit(x, y) {
34 if (x.value === null || x.value === undefined) throw new Error('Parameter x contains a unit with undefined value');
35 if (y.value === null || y.value === undefined) throw new Error('Parameter y contains a unit with undefined value');
36 if (!x.equalBase(y)) throw new Error('Units do not match');
37 var res = x.clone();
38 res.value = this(res.value, y.value);
39 res.fixPrefix = false;
40 return res;
41 }
42 });
43});
\No newline at end of file