Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ethanent/mathvm
Node math processing and execution
https://github.com/ethanent/mathvm
math math-expression-evaluator math-parser nodejs
Last synced: about 2 months ago
JSON representation
Node math processing and execution
- Host: GitHub
- URL: https://github.com/ethanent/mathvm
- Owner: ethanent
- License: mit
- Created: 2019-10-16T04:38:53.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-24T20:33:03.000Z (over 4 years ago)
- Last Synced: 2024-01-30T23:26:06.202Z (11 months 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)')
// => 1mathvm.exec('sin(pi / 2)', {}, [])
// Errors, function sin does not existmathvm.exec('sin(pi / 2)', {}, ['trig'])
// => 1
```