1 | ![math.js](https://raw.github.com/josdejong/mathjs/master/img/mathjs.png)
|
2 |
|
3 | [http://mathjs.org](http://mathjs.org)
|
4 |
|
5 | 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 different data types like numbers, big numbers, complex numbers, fractions, units, and matrices. Powerful and easy to use.
|
6 |
|
7 | [![Version](https://img.shields.io/npm/v/mathjs.svg)](https://www.npmjs.com/package/mathjs)
|
8 | [![Downloads](https://img.shields.io/npm/dm/mathjs.svg)](https://www.npmjs.com/package/mathjs)
|
9 | [![Build Status](https://img.shields.io/travis/josdejong/mathjs.svg)](https://travis-ci.org/josdejong/mathjs)
|
10 | ![Maintenance](https://img.shields.io/maintenance/yes/2018.svg)
|
11 | [![License](https://img.shields.io/github/license/josdejong/mathjs.svg)](https://github.com/josdejong/mathjs/blob/master/LICENSE)
|
12 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjosdejong%2Fmathjs.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjosdejong%2Fmathjs?ref=badge_shield)
|
13 |
|
14 | ## Features
|
15 |
|
16 | - Supports numbers, big numbers, complex numbers, fractions, units, strings, arrays, and matrices.
|
17 | - Is compatible with JavaScript's built-in Math library.
|
18 | - Contains a flexible expression parser.
|
19 | - Does symbolic computation.
|
20 | - Comes with a large set of built-in functions and constants.
|
21 | - Can be used as a command line application as well.
|
22 | - Runs on any JavaScript engine.
|
23 | - Is easily extensible.
|
24 | - Open source.
|
25 |
|
26 | ## Usage
|
27 |
|
28 | Math.js can be used in both node.js and in the browser.
|
29 |
|
30 | Install math.js using [npm](https://www.npmjs.com/package/mathjs):
|
31 |
|
32 | npm install mathjs
|
33 |
|
34 | Or download mathjs via one of the CDN's listed on the downloads page:
|
35 |
|
36 | [http://mathjs.org/download.html](http://mathjs.org/download.html#download)
|
37 |
|
38 | Math.js can be used similar to JavaScript's built-in Math library. Besides that,
|
39 | math.js can evaluate
|
40 | [expressions](http://mathjs.org/docs/expressions/index.html)
|
41 | and supports
|
42 | [chained operations](http://mathjs.org/docs/core/chaining.html).
|
43 |
|
44 | ```js
|
45 | // load math.js
|
46 | var math = require('mathjs');
|
47 |
|
48 | // functions and constants
|
49 | math.round(math.e, 3); // 2.718
|
50 | math.atan2(3, -3) / math.pi; // 0.75
|
51 | math.log(10000, 10); // 4
|
52 | math.sqrt(-4); // 2i
|
53 | math.pow([[-1, 2], [3, 1]], 2); // [[7, 0], [0, 7]]
|
54 | math.derivative('x^2 + x', 'x'); // 2 * x + 1
|
55 |
|
56 | // expressions
|
57 | math.eval('12 / (2.3 + 0.7)'); // 4
|
58 | math.eval('12.7 cm to inch'); // 5 inch
|
59 | math.eval('sin(45 deg) ^ 2'); // 0.5
|
60 | math.eval('9 / 3 + 2i'); // 3 + 2i
|
61 | math.eval('det([-1, 2; 3, 1])'); // -7
|
62 |
|
63 | // chaining
|
64 | math.chain(3)
|
65 | .add(4)
|
66 | .multiply(2)
|
67 | .done(); // 14
|
68 | ```
|
69 |
|
70 | See the [Getting Started](http://mathjs.org/docs/getting_started.html) for a more detailed tutorial.
|
71 |
|
72 |
|
73 | ## Browser support
|
74 |
|
75 | Math.js works on any ES5 compatible JavaScript engine: node.js 0.10, and Internet Explorer 9 and newer, and all other browsers (Chrome, Firefox, Safari). If support for old browsers like Internet Explorer 8 is required, the [es5-shim](https://github.com/kriskowal/es5-shim) library has to be loaded.
|
76 |
|
77 |
|
78 | ## Documentation
|
79 |
|
80 | - [Getting Started](http://mathjs.org/docs/getting_started.html)
|
81 | - [Examples](http://mathjs.org/examples/index.html)
|
82 | - [Overview](http://mathjs.org/docs/index.html)
|
83 | - [History](http://mathjs.org/history.html)
|
84 |
|
85 |
|
86 | ## Build
|
87 |
|
88 | First clone the project from github:
|
89 |
|
90 | git clone git://github.com/josdejong/mathjs.git
|
91 | cd mathjs
|
92 |
|
93 | Install the project dependencies:
|
94 |
|
95 | npm install
|
96 |
|
97 | Then, the project can be build by executing the build script via npm:
|
98 |
|
99 | npm run build
|
100 |
|
101 | This will build the library math.js and math.min.js from the source files and
|
102 | put them in the folder dist.
|
103 |
|
104 |
|
105 | ## Test
|
106 |
|
107 | To execute tests for the library, install the project dependencies once:
|
108 |
|
109 | npm install
|
110 |
|
111 | Then, the tests can be executed:
|
112 |
|
113 | npm test
|
114 |
|
115 | To test code coverage of the tests:
|
116 |
|
117 | npm run coverage
|
118 |
|
119 | To see the coverage results, open the generated report in your browser:
|
120 |
|
121 | ./coverage/lcov-report/index.html
|
122 |
|
123 | Automated cross browser testing for mathjs is generously provided by <a href="https://www.browserstack.com" target="_blank">BrowserStack</a>
|
124 |
|
125 | <a href="https://www.browserstack.com" target="_blank"><img alt="BrowserStack" src="https://raw.github.com/josdejong/mathjs/master/misc/browserstack.png"></a>
|
126 |
|
127 |
|
128 | ## License
|
129 |
|
130 | Copyright (C) 2013-2018 Jos de Jong <wjosdejong@gmail.com>
|
131 |
|
132 | Licensed under the Apache License, Version 2.0 (the "License");
|
133 | you may not use this file except in compliance with the License.
|
134 | You may obtain a copy of the License at
|
135 |
|
136 | http://www.apache.org/licenses/LICENSE-2.0
|
137 |
|
138 | Unless required by applicable law or agreed to in writing, software
|
139 | distributed under the License is distributed on an "AS IS" BASIS,
|
140 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
141 | See the License for the specific language governing permissions and
|
142 | limitations under the License.
|