Skip to content

JavaScript libraries for processing infix and RPN postfix strings

License

Notifications You must be signed in to change notification settings

felamaslen/calculator-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calculator lib

Provides functions for evaluating infix (and RPN postfix) expressions, in JavaScript.

Source is in ES6, released as ES5. Transpiled using Babel.

Installation:

npm install calculator-lib

Usage:

Evaluation of infix expressions

const { evaluateInfix } = require('calculator-lib');

evaluateInfix('4 + 5'); // -> 9

evaluateInfix('2+3/(5^-1)*-1.5'); // -> -20.5

Supported operators

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...

Other methods:

Evaluation of (RPN) postfix expressions

const { evaluatePostfix } = require('calculator-lib');

evaluatePostfix('1 2 + 3 +'); // -> 6

evaluatePostfix('21 -3.2 *'); // -> -67.2

Conversion of infix expressions to (RPN) postfix expressions

const { infixToPostfix } = require('calculator-lib');

infixToPostfix('21 ^ 3 * 2 - 10'); // -> '21 3 ^ 2 * 10 -'

About

JavaScript libraries for processing infix and RPN postfix strings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published