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