Gathering detailed insights and metrics for math-expression-evaluator
Gathering detailed insights and metrics for math-expression-evaluator
Gathering detailed insights and metrics for math-expression-evaluator
Gathering detailed insights and metrics for math-expression-evaluator
@types/math-expression-evaluator
Stub TypeScript definitions entry for math-expression-evaluator, which provides its own types definitions
expr-eval
Mathematical expression evaluator
subscript
Fast and tiny expression evaluator with minimal syntax.
nerdamer
javascript light-weight symbolic math expression evaluator
Math JS library. Super advanced & efficient Math expression evaluator
npm install math-expression-evaluator
Typescript
Module System
Node Version
NPM Version
TypeScript (62.77%)
JavaScript (36.82%)
Dockerfile (0.21%)
Shell (0.2%)
Total Downloads
620,556,729
Last Day
225,345
Last Week
1,141,614
Last Month
5,094,250
Last Year
58,395,275
MIT License
207 Stars
115 Commits
34 Forks
7 Watchers
12 Branches
8 Contributors
Updated on Apr 16, 2025
Minified
Minified + Gzipped
Latest Version
2.0.6
Package Id
math-expression-evaluator@2.0.6
Unpacked Size
66.41 kB
Size
17.80 kB
File Count
30
NPM Version
8.3.2
Node Version
16.20.2
Published on
Nov 18, 2024
Cumulative downloads
Total Downloads
Last Day
44.1%
225,345
Compared to previous day
Last Week
1.1%
1,141,614
Compared to previous week
Last Month
-1.6%
5,094,250
Compared to previous month
Last Year
4.2%
58,395,275
Compared to previous year
22
An extremely efficient, flexible and amazing evaluator for Math expression in Javascript.
Input | Result | Explanation |
---|---|---|
2+3-1 | 4 | Addition and Subtraction operator |
2*5/10 | 1 | Multiplication and Division operator |
tan45 or tan(45) | 1 | Trigonometric Function (tan in Degree mode) |
tan45 or tan(45) | 1.619775190543862 | Trigonometric Function (tan in Radian mode) |
Pi1,15,n or Pi(1,15,n) | 1307674368000 | Product of Sequence |
Sigma1,15,n or Sigma(1,15,n) | 120 | Sum of Sequence (also called summation) |
2^3 | 8 | Exponent (note this operator is left associative like MS Office) |
5P3 | 60 | Permutaion Method to calculate all the permutaions |
sincostan90 or sin(cos(tan(90))) | 0.017261434031253 | Multiple functions with or without parenthesis (both works) |
Using npm
npm install math-expression-evaluator
Using bower
bower install math-expression-evaluator
const mexp = new Mexp() var value = mexp.eval(exp); // 2 + 2
Create mexp object
const mexp = new Mexp
Parse an expression and then add additional detail to the tokens using
var lexed = mexp.lex("expression");
which returns an array of token which will be further processed by methods toPostfix and postfixEval
Now, that array is needed to be converted to postfix notation using
var postfixed = mexp.toPostfix(lexed);
which converts the array to postfix notation and return new array
Now to get the value of expression use postfixEval
var result = mexp.postfixEval(postfixed);
where result contains the result.
Defining a token
A token is defined similar way as 1.x version. You may refer to test file on examples on how to add tokens. Since this package is TS compatible, you will get autocomplete on mexp.addToken
Adding tokens using addToken method of mexp object
const mexp = new Mexp()
mexp.addToken([token1, token2]) // tokens once added will be preserved in later evaluations
Adding tokens using eval method of mexp object
const mexp = new Mexp()
mexp.eval("expression", [token1, token2]) // tokens once added will be preserved in later evaluations
Adding token using constituents of eval method of mexp object
const mexp = new Mexp()
const answer = mexp.postfixEval(mexp.toPostfix(mexp.lexed("expression", [token1, token2]))) // tokens once added will be preserved in later evaluations
console.log(answer)
npm test
Symbol | Explanation |
---|---|
+ | Addition Operator eg. 2+3 results 5 |
- | Subtraction Operator eg. 2-3 results -1 |
/ | Division operator eg 3/2 results 1.5 |
* | Multiplication Operator eg. 2*3 results 6 |
Mod | Modulus Operator eg. 3 Mod 2 results 1 |
( | Opening Parenthesis |
) | Closing Parenthesis |
& | Bitwise AND eg. 3&1 results 1 |
Sigma | Summation eg. Sigma(1,100,n) results 5050 |
Pi | Product eg. Pi(1,10,n) results 3628800 |
n | Variable for Summation or Product |
pi | Math constant pi returns 3.14 |
e | Math constant e returns 2.71 |
C | Combination operator eg. 4C2 returns 6 |
P | Permutation operator eg. 4P2 returns 12 |
! | factorial operator eg. 4! returns 24 |
log | logarithmic function with base 10 eg. log 1000 returns 3 |
ln | natural log function with base e eg. ln 2 returns .3010 |
pow | power function with two operator pow(2,3) returns 8 |
^ | power operator eg. 2^3 returns 8 |
root | underroot function root 4 returns 2 |
sin | Sine function |
cos | Cosine function |
tan | Tangent function |
asin | Inverse Sine function |
acos | Inverse Cosine function |
atan | Inverse Tangent function |
sinh | Hyperbolic Sine function |
cosh | Hyperbolic Cosine function |
tanh | Hyperbolic Tangent function |
asinh | Inverse Hyperbolic Sine function |
acosh | Inverse Hyperbolic Cosine function |
atanh | Inverse Hyperbolic Tangent function |
This is a fantastic feature of this calculator that it is capable of evaluating expressions containing Sigma and Pi.
Passing Sigma(1,100,n)
will evaluate to 5050 as n is summationed from 1 to 100.
and Pi(1,15,n) will evaluate to 1307674368000 as n is multiplied from 1 to 15 which is equal to 15!
If a expression is readable by human then it is readable by this evaluator. There is no need to wrap every function inside parenthesis. For eg. sin90 will work totally fine instead of sin(90)
##Changelog
This will reflect in next release named v1.2.16
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
Found 3/26 approved changesets -- score normalized to 1
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
32 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More