Comparing version 0.5.0 to 0.6.0
{ | ||
"name": "mathjs", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features real and complex numbers, units, matrices, a large set of mathematical functions, and a flexible expression parser.", | ||
@@ -5,0 +5,0 @@ "author": "Jos de Jong <wjosdejong@gmail.com>", |
@@ -14,5 +14,6 @@  | ||
- Supports numbers, complex numbers, units, strings, arrays, and matrices. | ||
- Contains a large set of built-in functions and constants. | ||
- Contains a flexible expression parser. | ||
- Compatible with JavaScript’s built-in Math library. | ||
- Supports chained operations. | ||
- A large set of built-in functions and constants. | ||
- No dependencies. Runs on any JavaScript engine. | ||
@@ -89,3 +90,21 @@ - Easily extensible. | ||
Operations can be performed using: | ||
- regular function calls | ||
- chained operations (see [Selector](#selector)) | ||
- expression parsing (see [Parser](#parser)) | ||
```js | ||
// regular function call | ||
math.subtract(math.add(3, 4), 2); // 5 | ||
// chained operation | ||
math.select(3).add(4).subtract(2).done(); // 5 | ||
// expression parser | ||
var parser = math.parser(); | ||
parser.eval('3 + 4 - 2'); // 5 | ||
``` | ||
## Parser | ||
@@ -146,2 +165,44 @@ | ||
## Selector | ||
Math.js supports chaining operations by wrapping a value into a `Selector`. | ||
A selector can be created with the method `math.select(value)`. | ||
All methods available in the math namespace can be executed via the selector. | ||
The methods will be executed with the selectors value as first argument, | ||
followed by extra arguments provided by the method call itself. | ||
```js | ||
math.select(3) | ||
.add(4) | ||
.subtract(2) | ||
.done(); | ||
// 5 | ||
math.select( [[1, 2], [3, 4]] ) | ||
.set([1, 1], 8) | ||
.multiply(3) | ||
.done(); | ||
// [[24, 6], [9, 12]] | ||
``` | ||
The Selector has a number of special functions: | ||
- `done()` | ||
Finalize the chained operation and return the selectors value. | ||
- `valueOf()` | ||
The same as `done()`, returns the selectors value. | ||
- `toString()` | ||
Executes `math.format(value)` onto the selectors value, returning | ||
a string representation of the value. | ||
- `get(index)` | ||
Get a subselection of the selectors value. Only applicable when | ||
the value has a method get, for example when value is a Matrix | ||
or Array. | ||
- `set(index, replacement)` | ||
Replace a subselection of the selectors value. Only applicable | ||
when the value has a method get, for example when value is a | ||
Matrix or Array. | ||
## Workspace | ||
@@ -212,6 +273,9 @@ | ||
Math.js supports complex numbers. | ||
Math.js supports complex numbers. Most methods can be executed with complex | ||
numbers as arguments. | ||
```js | ||
var a = math.complex(2, 3); // 2 + 3i | ||
a.re; // 2 | ||
a.im; // 3 | ||
var b = math.complex('4 - 2i'); // 4 - 2i | ||
@@ -224,3 +288,7 @@ math.add(a, b); // 6 + i | ||
Math.js supports units. | ||
Math.js supports units. Basic operations `add`, `subtract`, `multiply`, | ||
and `divide` can be performed on units. | ||
Trigonometric methods like `sin` support units with an angle as argument. | ||
Units can be converted from one to another using method `in`, | ||
an the value of a unit can be retrieved using `toNumber`. | ||
@@ -231,5 +299,8 @@ ```js | ||
math.add(a, b); // 0.65 m | ||
b.in('cm'); // 10 cm Alternatively: math.in(b, 'cm') | ||
b.toNumber('cm'); // 10 | ||
var parser = math.parser(); | ||
parser.eval('2 inch in cm'); // 5.08 cm | ||
parser.eval('cos(45 deg)'); // 0.7071067811865476 | ||
``` | ||
@@ -326,4 +397,6 @@ | ||
- math.floor(x) | ||
- math.gcd(a, b, c, ...) | ||
- math.larger(x, y) | ||
- math.largereq(x, y) | ||
- math.lcm(a, b, c, ...) | ||
- math.log(x [, base]) | ||
@@ -395,4 +468,4 @@ - math.log10(x) | ||
- math.format([template, ] values) | ||
- math.help(fn) | ||
- math.import(filename | object, override) | ||
- math.select([x]) | ||
- math.typeof(x) | ||
@@ -496,2 +569,4 @@ | ||
- Version 0.6.0 | ||
- Implement chained operations | ||
- Version 0.7.0 | ||
- More on matrices | ||
@@ -498,0 +573,0 @@ - Version 1.0.0 |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
584
381763
8359