Solve math expressions or create equations for repeated and complex Math tasks.
To use in browser, download
A similar library I wrote in Haskell is also available mathexpr
Install using npm:
npm install equations
// solveconsole; // 32// equationlet sphereArea = Equation;console; // 314.1592653589793let test = Equation;consoleto;
You can also register your own operators and constants.
// these options are explained in [`operators.js`]().Equation;Equation; // 0.5Equation; // 0.2Equation;Equation; // a number between 10 and 20// Complex operatorsEquation; // 60
Takes a math expression and evaluates it, returning the result.
Takes a math expression containing variables, returning a function which replaces the variables with given arguments, and solves the expression.
registerOperator(key: String, options: Object)
Registers a new operator.
The function which is run on arguments and returns the result
The format which specifies how arguments are placed relative to operator, this is a string in which 1 represents the operator and zeroes represent arguments.
+ has the format
010 and factorial has
Specifies the precedence of operator. The less the value, the higher the precedence, resulting in sooner execution.
registerConstant(key: String, value: Function/Number)
Registers a new constant. value can be a function (takes no arguments), or a constant number.
That's right, we have named these constants but they actually can change, that's why we can use functions to define them. An example is the
RAND constant which calls
The code is commented and I hope you don't have a hard time contributing, anyway, some tips about contributing:
The source code is in
lib directory and is then transpiled into
Transpiles, browserifies, uglifies
Runs ESLint on
Runs the tests
Please make sure to run
grunt eslint before commiting.
If you're adding something new, please add a test, too.