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. Powerful and easy to use.
Here some example code demonstrating how to use the library. More examples are available here.
// load math.js var math = require('mathjs'); // functions and constants math.round(math.e, 3); // 2.718 math.atan2(3, -3) / math.pi; // 0.75 math.log(1000, 10); // 3 math.sqrt(-4); // 2i math.pow([[-1, 2], [3, 1]], 2); // [[7, 0], [0, 7]] // expressions math.eval('1.2 / (2.3 + 0.7)'); // 0.4 math.eval('5.08 cm in inch'); // 2 inch math.eval('sin(45 deg) ^ 2'); // 0.5 math.eval('9 / 3 + 2i'); // 3 + 2i math.eval('det([-1, 2; 3, 1])'); // -7 // chained operations math.select(3) .add(4) .multiply(2) .done(); // 14
Try the expression parser below.
Math.js can be installed using npm:
npm install mathjs
The latest version of math.js can be downloaded below:
| Development (version 0.8.2) | 279 kB, uncompressed with comments |
| Production (version 0.8.2) | 20 kB, minified and gzipped |
Documentation and source code can be found on github:
https://github.com/josdejong/mathjs
Math.js is open source and licensend under the Apache 2.0 License.