UNPKG

6.08 kBMarkdownView Raw
1![math.js](https://raw.github.com/josdejong/mathjs/master/misc/img/mathjs.png)
2
3[https://mathjs.org](https://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/master.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/2020.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
30Math.js can be used in both node.js and in the browser.
31
32Install 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
38Or 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
42Math.js can be used similar to JavaScript's built-in Math library. Besides that,
43math.js can evaluate
44[expressions](https://mathjs.org/docs/expressions/index.html)
45and supports
46[chained operations](https://mathjs.org/docs/core/chaining.html).
47
48```js
49import {
50 atan2, chain, derivative, e, evaluate, log, pi, pow, round, sqrt
51} from 'mathjs'
52
53// functions and constants
54round(e, 3) // 2.718
55atan2(3, -3) / pi // 0.75
56log(10000, 10) // 4
57sqrt(-4) // 2i
58pow([[-1, 2], [3, 1]], 2) // [[7, 0], [0, 7]]
59derivative('x^2 + x', 'x') // 2 * x + 1
60
61// expressions
62evaluate('12 / (2.3 + 0.7)') // 4
63evaluate('12.7 cm to inch') // 5 inch
64evaluate('sin(45 deg) ^ 2') // 0.5
65evaluate('9 / 3 + 2i') // 3 + 2i
66evaluate('det([-1, 2; 3, 1])') // -7
67
68// chaining
69chain(3)
70 .add(4)
71 .multiply(2)
72 .done() // 14
73```
74
75See the [Getting Started](https://mathjs.org/docs/getting_started.html) for a more detailed tutorial.
76
77
78## Browser support
79
80Math.js works on any ES5 compatible JavaScript engine: node.js, Chrome, Firefox, Safari, Edge, and IE11.
81
82
83## Documentation
84
85- [Getting Started](https://mathjs.org/docs/getting_started.html)
86- [Examples](https://mathjs.org/examples/index.html)
87- [Overview](https://mathjs.org/docs/index.html)
88- [History](https://mathjs.org/history.html)
89
90
91## Build
92
93First clone the project from github:
94
95 git clone git://github.com/josdejong/mathjs.git
96 cd mathjs
97
98Install the project dependencies:
99
100 npm install
101
102Then, the project can be build by executing the build script via npm:
103
104 npm run build
105
106This will build the library math.js and math.min.js from the source files and
107put them in the folder dist.
108
109
110## Test
111
112To execute tests for the library, install the project dependencies once:
113
114 npm install
115
116Then, the tests can be executed:
117
118 npm test
119
120Additionally, the tests can be run on FireFox using [headless mode](https://developer.mozilla.org/en-US/Firefox/Headless_mode):
121
122 npm run test:browser
123
124To 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:
125
126 npm run test:browserstack
127
128To test code coverage of the tests:
129
130 npm run coverage
131
132To see the coverage results, open the generated report in your browser:
133
134 ./coverage/lcov-report/index.html
135
136
137### Continuous integration testing
138
139Continuous 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.
140The 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.
141
142[![Travis CI](https://raw.github.com/josdejong/mathjs/develop/misc/Travis-CI-logo.png)](https://travis-ci.org/)    
143[![BrowserStack](https://raw.github.com/josdejong/mathjs/master/misc/browserstack.png)](https://www.browserstack.com)
144
145Thanks Travis CI and BrowserStack for the generous free hosting of this open source project!
146
147## License
148
149Copyright (C) 2013-2020 Jos de Jong <wjosdejong@gmail.com>
150
151Licensed under the Apache License, Version 2.0 (the "License");
152you may not use this file except in compliance with the License.
153You may obtain a copy of the License at
154
155 https://www.apache.org/licenses/LICENSE-2.0
156
157Unless required by applicable law or agreed to in writing, software
158distributed under the License is distributed on an "AS IS" BASIS,
159WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
160See the License for the specific language governing permissions and
161limitations under the License.