/mathvm

Node math processing and execution

Primary LanguageJavaScriptMIT LicenseMIT

mathvm

Node math processing and execution VM

GitHub | NPM

Install

npm i mathvm
const mathvm = require('mathvm')

Use

mathvm.exec('1 + 5')
// => 6
mathvm.exec('7 + x ^ 2', {
	'vars': {
		'x': 2
	}
})
// => 11
mathvm.exec('asin(cos(pi))')
// => -Pi/2
mathvm.exec('5 * add(x, 3)', {
	'functions': {
		'add': (a, b) => a + b
	},
	'vars': {
		'x': 2
	}
})
// => 25

EnvSets

mathvm.exec('sin(pi / 2)')
// => 1

mathvm.exec('sin(pi / 2)', {}, [])
// Errors, function sin does not exist

mathvm.exec('sin(pi / 2)', {}, ['trig'])
// => 1