https://github.com/ethan7g/mathvm
Node math processing and execution
https://github.com/ethan7g/mathvm
math math-expression-evaluator math-parser nodejs
Last synced: 12 months ago
JSON representation
Node math processing and execution
- Host: GitHub
- URL: https://github.com/ethan7g/mathvm
- Owner: ethan7g
- License: mit
- Archived: true
- Created: 2019-10-16T04:38:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-24T20:33:03.000Z (almost 6 years ago)
- Last Synced: 2025-03-03T07:13:58.620Z (about 1 year ago)
- Topics: math, math-expression-evaluator, math-parser, nodejs
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mathvm
> Node math processing and execution VM
[GitHub](https://github.com/ethanent/mathvm) | [NPM](https://www.npmjs.com/package/mathvm)
## Install
```
npm i mathvm
```
```js
const mathvm = require('mathvm')
```
## Use
```js
mathvm.exec('1 + 5')
// => 6
```
```js
mathvm.exec('7 + x ^ 2', {
'vars': {
'x': 2
}
})
// => 11
```
```js
mathvm.exec('asin(cos(pi))')
// => -Pi/2
```
```js
mathvm.exec('5 * add(x, 3)', {
'functions': {
'add': (a, b) => a + b
},
'vars': {
'x': 2
}
})
// => 25
```
## EnvSets
```js
mathvm.exec('sin(pi / 2)')
// => 1
mathvm.exec('sin(pi / 2)', {}, [])
// Errors, function sin does not exist
mathvm.exec('sin(pi / 2)', {}, ['trig'])
// => 1
```