mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
1.2 KiB
1.2 KiB
Function add
Add two values, x + y.
For matrices, the function is evaluated element wise.
Syntax
math.add(x, y)
Parameters
| Parameter | Type | Description |
|---|---|---|
x |
number | BigNumber | Fraction | Complex | Unit | Array | Matrix | First value to add |
y |
number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Second value to add |
Returns
| Type | Description |
|---|---|
| number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Sum of x and y |
Examples
math.add(2, 3); // returns number 5
var a = math.complex(2, 3);
var b = math.complex(-4, 1);
math.add(a, b); // returns Complex -2 + 4i
math.add([1, 2, 3], 4); // returns Array [5, 6, 7]
var c = math.unit('5 cm');
var d = math.unit('2.1 mm');
math.add(c, d); // returns Unit 52.1 mm
math.add("2.3", "4"); // returns number 6.3