UNPKG

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