Calculate infix / postfix expressions
npm install calculator-libProvides functions for evaluating infix (and RPN postfix) expressions, in JavaScript.
Source is in ES6, released as ES5. Transpiled using Babel.
npm install calculator-lib
``javascript
const { evaluateInfix } = require('calculator-lib');
evaluateInfix('4 + 5'); // -> 9
evaluateInfix('2+3/(5^-1)*-1.5'); // -> -20.5
`
Currently, operations are limited to the following:
- Multiplication (*)/
- Division ()+
- Addition ()-
- Subtraction ()^
- Exponentiation ()
Feel free to add more in a pull request! For example, trigonometric operations would come in handy...
`javascript
const { evaluatePostfix } = require('calculator-lib');
evaluatePostfix('1 2 + 3 +'); // -> 6
evaluatePostfix('21 -3.2 *'); // -> -67.2
`
`javascript
const { infixToPostfix } = require('calculator-lib');
infixToPostfix('21 ^ 3 2 - 10'); // -> '21 3 ^ 2 10 -'
``