1 | ![math.js](https://raw.github.com/josdejong/mathjs/master/img/mathjs.png)
|
2 |
|
3 | [https://mathjs.org](https://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 | [![Greenkeeper badge](https://badges.greenkeeper.io/josdejong/mathjs.svg)](https://greenkeeper.io/)
|
11 | [![Maintenance](https://img.shields.io/maintenance/yes/2019.svg)](https://github.com/josdejong/mathjs/graphs/commit-activity)
|
12 | [![License](https://img.shields.io/github/license/josdejong/mathjs.svg)](https://github.com/josdejong/mathjs/blob/master/LICENSE)
|
13 | [![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)
|
14 | [![Slack](https://slack.bri.im/badge.svg)](https://slack.bri.im)
|
15 |
|
16 | ## Features
|
17 |
|
18 | - Supports numbers, big numbers, complex numbers, fractions, units, strings, arrays, and matrices.
|
19 | - Is compatible with JavaScript's built-in Math library.
|
20 | - Contains a flexible expression parser.
|
21 | - Does symbolic computation.
|
22 | - Comes with a large set of built-in functions and constants.
|
23 | - Can be used as a command line application as well.
|
24 | - Runs on any JavaScript engine.
|
25 | - Is easily extensible.
|
26 | - Open source.
|
27 |
|
28 | ## Usage
|
29 |
|
30 | Math.js can be used in both node.js and in the browser.
|
31 |
|
32 | Install math.js using [npm](https://www.npmjs.com/package/mathjs):
|
33 |
|
34 | npm install mathjs
|
35 |
|
36 | > Note that when using mathjs in a TypeScript project, you will have to install type definition files too: `npm install @types/mathjs`.
|
37 |
|
38 | Or download mathjs via one of the CDN's listed on the downloads page:
|
39 |
|
40 | [https://mathjs.org/download.html](https://mathjs.org/download.html#download)
|
41 |
|
42 | Math.js can be used similar to JavaScript's built-in Math library. Besides that,
|
43 | math.js can evaluate
|
44 | [expressions](https://mathjs.org/docs/expressions/index.html)
|
45 | and supports
|
46 | [chained operations](https://mathjs.org/docs/core/chaining.html).
|
47 |
|
48 | ```js
|
49 | // load math.js
|
50 | const math = require('mathjs')
|
51 |
|
52 | // functions and constants
|
53 | math.round(math.e, 3) // 2.718
|
54 | math.atan2(3, -3) / math.pi // 0.75
|
55 | math.log(10000, 10) // 4
|
56 | math.sqrt(-4) // 2i
|
57 | math.pow([[-1, 2], [3, 1]], 2) // [[7, 0], [0, 7]]
|
58 | math.derivative('x^2 + x', 'x') // 2 * x + 1
|
59 |
|
60 | // expressions
|
61 | math.eval('12 / (2.3 + 0.7)') // 4
|
62 | math.eval('12.7 cm to inch') // 5 inch
|
63 | math.eval('sin(45 deg) ^ 2') // 0.5
|
64 | math.eval('9 / 3 + 2i') // 3 + 2i
|
65 | math.eval('det([-1, 2 3, 1])') // -7
|
66 |
|
67 | // chaining
|
68 | math.chain(3)
|
69 | .add(4)
|
70 | .multiply(2)
|
71 | .done() // 14
|
72 | ```
|
73 |
|
74 | See the [Getting Started](https://mathjs.org/docs/getting_started.html) for a more detailed tutorial.
|
75 |
|
76 |
|
77 | ## Browser support
|
78 |
|
79 | Math.js works on any ES5 compatible JavaScript engine: node.js 4 or newer, Chrome, Firefox, Safari, Edge, and IE11.
|
80 |
|
81 | Though there is no official support for older browsers, math.js should still work on older browsers
|
82 | when using the [es5-shim](https://github.com/kriskowal/es5-shim).
|
83 |
|
84 |
|
85 | ## Documentation
|
86 |
|
87 | - [Getting Started](https://mathjs.org/docs/getting_started.html)
|
88 | - [Examples](https://mathjs.org/examples/index.html)
|
89 | - [Overview](https://mathjs.org/docs/index.html)
|
90 | - [History](https://mathjs.org/history.html)
|
91 |
|
92 |
|
93 | ## Build
|
94 |
|
95 | First clone the project from github:
|
96 |
|
97 | git clone git://github.com/josdejong/mathjs.git
|
98 | cd mathjs
|
99 |
|
100 | Install the project dependencies:
|
101 |
|
102 | npm install
|
103 |
|
104 | Then, the project can be build by executing the build script via npm:
|
105 |
|
106 | npm run build
|
107 |
|
108 | This will build the library math.js and math.min.js from the source files and
|
109 | put them in the folder dist.
|
110 |
|
111 |
|
112 | ## Test
|
113 |
|
114 | To execute tests for the library, install the project dependencies once:
|
115 |
|
116 | npm install
|
117 |
|
118 | Then, the tests can be executed:
|
119 |
|
120 | npm test
|
121 |
|
122 | Additionally, the tests can be run on FireFox using [headless mode](https://developer.mozilla.org/en-US/Firefox/Headless_mode):
|
123 |
|
124 | npm run test:browser
|
125 |
|
126 | To run the tests remotely on BrowserStack, first set the environment variables `BROWSER_STACK_USERNAME` and `BROWSER_STACK_ACCESS_KEY` with your username and access key and then execute:
|
127 |
|
128 | npm run test:browserstack
|
129 |
|
130 | To test code coverage of the tests:
|
131 |
|
132 | npm run coverage
|
133 |
|
134 | To see the coverage results, open the generated report in your browser:
|
135 |
|
136 | ./coverage/lcov-report/index.html
|
137 |
|
138 |
|
139 | ### Continuous integration testing
|
140 |
|
141 | Continuous integration tests are run on [Travis CI](https://travis-ci.org/) and [BrowserStack](https://www.browserstack.com) every time a commit is pushed to github.
|
142 | The test results can be checked on https://travis-ci.org/josdejong/mathjs. Travis CI runs the tests for different versions of node.js, and BrowserStack runs the tests are run on all major browsers.
|
143 |
|
144 | [![Travis CI](https://raw.github.com/josdejong/mathjs/develop/misc/Travis-CI-logo.png)](https://travis-ci.org/)
|
145 | [![BrowserStack](https://raw.github.com/josdejong/mathjs/master/misc/browserstack.png)](https://www.browserstack.com)
|
146 |
|
147 | Thanks Travis CI and BrowserStack for the generous free hosting of this open source project!
|
148 |
|
149 | ## License
|
150 |
|
151 | Copyright (C) 2013-2019 Jos de Jong <wjosdejong@gmail.com>
|
152 |
|
153 | Licensed under the Apache License, Version 2.0 (the "License");
|
154 | you may not use this file except in compliance with the License.
|
155 | You may obtain a copy of the License at
|
156 |
|
157 | https://www.apache.org/licenses/LICENSE-2.0
|
158 |
|
159 | Unless required by applicable law or agreed to in writing, software
|
160 | distributed under the License is distributed on an "AS IS" BASIS,
|
161 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
162 | See the License for the specific language governing permissions and
|
163 | limitations under the License.
|