Skip to content

joemaidman/arithmio

Repository files navigation

Arithmio Build Status

 ||  |   ___         ___        ||  |
 || _|__/  _\_______/  _\_______|| _|
 ||(___(  (________(  (_________||((_)
 ||  |  \___/       \___/       ||  |
 || _|________/  _\_____________|| _|
 ||(_________(  (_______________||((_)
 ||  |        \___/             ||  |

A maths expression parser and calculator.

Converts infix to postfix expressions and calculates the result.

Installation

'arithmio' is available as an npm package:

$ npm install arithmio

or as a RESTful API.

Usage

evaluate(infixExpression: string): number

calculates the result of infixExpression.

convertInfixToPostfix(expression: string): string

returns a postfix string of expression

calculate(postfixExpression: string): number

calculates the result of postfixExpression

Basic example test file

var evaluate = require("arithmio").evaluate;

/* es6 import
import { evaluate } from 'arithmio';
*/

const infixExpression = "1 + 1";

const result = evaluate(infixExpression); // 2

Operators

+

Adds the first operand to the second operand

-

Subtracts the first operand from the second operand.

*

Multiplies the first operand by the second operand.

/

Divides the first operand by the second operand.

^

Raises the first operand to the power of the second operand e.g. '10^6'.

Arithmetics

Shorthand to perform common arithmetic operations.

SQRT(n)

returns the square-root of n.

Constants

Shorthand to access mathmatical constants.

PI

returns the value of PI.

Helpers

SUM(x, y, z...)

Returns the sum of all operands passed.

Future development

  • Logical operators
  • Additional helper functions

About

A maths expression parser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published