Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

ethanent/mathvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published