UNPKG

5.06 kBMarkdownView Raw
1![math.js](https://raw.github.com/josdejong/mathjs/master/img/mathjs.png)
2
3[http://mathjs.org](http://mathjs.org)
4
5Math.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
28Math.js can be used in both node.js and in the browser.
29
30Install math.js using [npm](https://www.npmjs.com/package/mathjs):
31
32 npm install mathjs
33
34Or 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
38Math.js can be used similar to JavaScript's built-in Math library. Besides that,
39math.js can evaluate
40[expressions](http://mathjs.org/docs/expressions/index.html)
41and supports
42[chained operations](http://mathjs.org/docs/core/chaining.html).
43
44```js
45// load math.js
46var math = require('mathjs');
47
48// functions and constants
49math.round(math.e, 3); // 2.718
50math.atan2(3, -3) / math.pi; // 0.75
51math.log(10000, 10); // 4
52math.sqrt(-4); // 2i
53math.pow([[-1, 2], [3, 1]], 2); // [[7, 0], [0, 7]]
54math.derivative('x^2 + x', 'x'); // 2 * x + 1
55
56// expressions
57math.eval('12 / (2.3 + 0.7)'); // 4
58math.eval('12.7 cm to inch'); // 5 inch
59math.eval('sin(45 deg) ^ 2'); // 0.5
60math.eval('9 / 3 + 2i'); // 3 + 2i
61math.eval('det([-1, 2; 3, 1])'); // -7
62
63// chaining
64math.chain(3)
65 .add(4)
66 .multiply(2)
67 .done(); // 14
68```
69
70See the [Getting Started](http://mathjs.org/docs/getting_started.html) for a more detailed tutorial.
71
72
73## Browser support
74
75Math.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
88First clone the project from github:
89
90 git clone git://github.com/josdejong/mathjs.git
91 cd mathjs
92
93Install the project dependencies:
94
95 npm install
96
97Then, the project can be build by executing the build script via npm:
98
99 npm run build
100
101This will build the library math.js and math.min.js from the source files and
102put them in the folder dist.
103
104
105## Test
106
107To execute tests for the library, install the project dependencies once:
108
109 npm install
110
111Then, the tests can be executed:
112
113 npm test
114
115To test code coverage of the tests:
116
117 npm run coverage
118
119To see the coverage results, open the generated report in your browser:
120
121 ./coverage/lcov-report/index.html
122
123Automated 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
130Copyright (C) 2013-2018 Jos de Jong <wjosdejong@gmail.com>
131
132Licensed under the Apache License, Version 2.0 (the "License");
133you may not use this file except in compliance with the License.
134You may obtain a copy of the License at
135
136 http://www.apache.org/licenses/LICENSE-2.0
137
138Unless required by applicable law or agreed to in writing, software
139distributed under the License is distributed on an "AS IS" BASIS,
140WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141See the License for the specific language governing permissions and
142limitations under the License.