UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

82 lines • 2.67 kB
import { factory } from '../../utils/factory.js'; import { createMatAlgo01xDSid } from '../../type/matrix/utils/matAlgo01xDSid.js'; import { createMatAlgo04xSidSid } from '../../type/matrix/utils/matAlgo04xSidSid.js'; import { createMatAlgo10xSids } from '../../type/matrix/utils/matAlgo10xSids.js'; import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js'; var name = 'add'; var dependencies = ['typed', 'matrix', 'addScalar', 'DenseMatrix']; export var createAdd = /* #__PURE__ */factory(name, dependencies, _ref => { var typed = _ref.typed, matrix = _ref.matrix, addScalar = _ref.addScalar, DenseMatrix = _ref.DenseMatrix; var matAlgo01xDSid = createMatAlgo01xDSid({ typed }); var matAlgo04xSidSid = createMatAlgo04xSidSid({ typed }); var matAlgo10xSids = createMatAlgo10xSids({ typed, DenseMatrix }); var matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix }); /** * Add two or more values, `x + y`. * For matrices, the function is evaluated element wise. * * Syntax: * * math.add(x, y) * math.add(x, y, z, ...) * * Examples: * * math.add(2, 3) // returns number 5 * math.add(2, 3, 4) // returns number 9 * * const a = math.complex(2, 3) * const b = math.complex(-4, 1) * math.add(a, b) // returns Complex -2 + 4i * * math.add([1, 2, 3], 4) // returns Array [5, 6, 7] * * const c = math.unit('5 cm') * const d = math.unit('2.1 mm') * math.add(c, d) // returns Unit 5.21 cm * * math.add("2.3", "4") // returns number 6.3 * * See also: * * subtract, sum * * History: * * v11.6 Support matrix broadcasting * v5.0.3 Support matrices with a `datatype` defined * v3.8 Allow more than two arguments * * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} x First value to add * @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} y Second value to add * @return {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} Sum of `x` and `y` */ return typed(name, { 'any, any': addScalar, 'any, any, ...any': typed.referToSelf(self => (x, y, rest) => { var result = self(x, y); for (var i = 0; i < rest.length; i++) { result = self(result, rest[i]); } return result; }) }, matrixAlgorithmSuite({ elop: addScalar, DS: matAlgo01xDSid, SS: matAlgo04xSidSid, Ss: matAlgo10xSids })); });