UNPKG

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