@olamide203/math-expression

0.1.1 • Public • Published

math-expression

Version License: MIT GitHub release (latest by date) Build Status

math-expression is a simple math expression parser and evaluator for JavaScript and TypeScript. it uses decimal.js to ensure precision of floating point calculations.

Features

  • supports implicit multiplication and parenthesis grouping
  • Binary and unary operators are supported
  • supports mathematical functions
  • Precision and rounding mode can be configured

Installation

MathExpression can be used in both node.js and in the browser.

Install via npm:

npm install @olamide203/math-expression

Usage

import MathExpression from '@olamide203/math-expression';

new MathExpression('0.1 + 0.2').evaluate(); // 0.3
new MathExpression('2 * 6 / 3').evaluate(); // 4

// using unary prefix operators
new MathExpression('- 1 + 2').evaluate(); // 1
new MathExpression('+ 1 - - 2').evaluate(); // 3

// implicit multiplication
new MathExpression('2(6 / 3)').evaluate(); // 4

//Trig Functions
new MathExpression('sin(π)').evaluate(); // 0
new MathExpression('cos(pi / 2)').evaluate(); // -0.5

// Even more complex expressions
new MathExpression('2(4(6 / 3 + 2) + 2^3 / - 2(2.5!))').evaluate(); //5.413192236417259652

Package Sidebar

Install

npm i @olamide203/math-expression

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

182 kB

Total Files

7

Last publish

Collaborators

  • olamide203