Socket
Book a DemoInstallSign in
Socket

@artginzburg/calc

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@artginzburg/calc

Evaluate mathematical expressions

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

calc

Calculates mathematical expressions

The calc function takes a string argument and returns the value of the resulting calculation.

Install

npm install @motardo/calc

Usage

var calc = require("@motardo/calc");

calc("1+2")          // 3
calc("-1 / 2")       // -0.5
calc("2 + 3 * 4")    // 14
calc("(2+3)*4")      // 20
calc("5^2")          // 25

Demo

Try it out at https://motardo.github.io/calc/web/index.html

Testing

Run the tests with:

npm test

About

calc uses the shunting yard algorithm and two separate stacks, one for numerical values, and one for operators. The operators currently supported are + - * / and ^. Parenthesis can be used to override operator precedence.

TODO

  • Add support for shorthand scientific notation as in 1e9 for 1 billion
  • Add support for trigonometric functions
  • Add support for log and ln notation

Bugs

Bug reports and contributions are welcome. Open an issue on github or email the author at nswilson@gmail.com

Keywords

mathematic

FAQs

Package last updated on 30 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts