
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
complex-expression-parser
Advanced tools
Parses and evaluates expressions over the complex numbers
Complex Expression Parser parses mathematical expression strings over the field of complex numbers.
If you want to use it in a browser:
es5/expression.js
or es5/expression.min.js
before your scripts.Array
or Number
.For node.js
just run
npm install complex-expression-parser
If you are running in an environment that supports ES6 then you may begin using
Expression
in your code using
import Complex from './es6/complex.js';
import Expression from './es6/expression.js';
ES6 environments can use the Complex and ComplexMath classes directly by importing their respective files.
Expression
has a single method: evaluate
.
Expression
takes a single string as an argument to its constructor. This
string should be a valid mathematical expression. Any symbol which is not known
to the parser is interpreted as a variable. If the expression is not
syntactically valid then the constructor throws an exception.
// Create an expression for the equation 2x^2 + 3x - i where i is the
// imaginary constant
const expression = new Expression('2x * x + 3x - i');
evaluate
takes a single, optional dictionary of symbols and their values and
returns the value of the expression as a Complex
. If the expression has any
unset variables then this method throws an exception.
const expression = new Expression('2x + i');
const valueA = expression.evaluate({'x': new Complex(2, 4)}); // valueA is 6 + 9i
const valueB = expression.evaluate({'x': 2}); // valueB is 4 + i
const noValue = expression.evaluate(); // throws exception
Symbols can be any number of alphabetic characters followed by any number of digits or can be a single Unicode character.
Example symbols:
x
yy
M104
☃
\uD83D\uDE80
Example non-symbols:
i
- Known constant2x
- Interpreted as 2 * x
M104M
- Interpreted as M104 * M
☃☃
- Interpreted as ☃ * ☃
\uD83D\uDE80\uD83D\uDE80
- Interpreted as \uD83D\uDE80 * \uD83D\uDE80
e
: Euler's constanti
: The imaginary unitpi
: The ratio of a circle's circumference to its diameter+
(unary): The identity function+
(binary): Addition-
(unary): Negation-
(binary): Subtraction*
: Multiplication/
: Divisionabs(x)
: The magnitude of x
arg(x)
: The phase of x
ceil(x)
: The ceiling of x
conj(x)
: The conjugate of x
exp(x)
: The exponential of x
floor(x)
: The floor of x
frac(x)
: The fractional part of x
imag(x)
: The imaginary part of x
ℑ(x)
: The imaginary part of x
lg(x)
: The log base 2 of x
ln(x)
: The natural log of x
log(base, x)
: The log base base
of x
log10(x)
: The log base 10 of x
mod(x, y)
: x
mod y
nint(x)
: The nearest integer of x
norm(x)
: The norm of x
pow(base, power)
: base
raised to the power of power
real(x)
: The real part of x
ℜ(x)
: The real part of x
sqrt(x)
: The square root of x
arccos(x)
: The inverse cosine of x
arccosh(x)
: The inverse hyperbolic cosine of x
arccot(x)
: The inverse cotangent of x
arccoth(x)
: The inverse hyperbolic cotangent of x
arccsc(x)
: The inverse cosecant of x
arccsch(x)
: The inverse hyperbolic cosecant of x
arcsec(x)
: The inverse secant of x
arcsech(x)
: The inverse hyperbolic secant of x
arcsin(x)
: The inverse sine of x
arcsinh(x)
: The inverse hyperbolic sine of x
arctan(x)
: The inverse tangent of x
arctanh(x)
: The inverse hyperbolic tangent of x
cos(x)
: The cosine of x
cosh(x)
: The hyperbolic cosine of x
cot(x)
: The cotangent of x
coth(x)
: The hyperbolic cotangent of x
csc(x)
: The cosecant of x
csch(x)
: The hyperbolic cosecant of x
sec(x)
: The secant of x
sech(x)
: The hyperbolic secant of x
sin(x)
: The sine of x
sinh(x)
: The hyperbolic sine of x
tan(x)
: The tangent of x
tanh(x)
: The hyperbolic tangent of x
gamma(x)
: The gamma of x
Γ(x)
: The gamma of x
Submit a pull request and mail colinjeanne@hotmail.com.
Development should occur against the ES6 files. Build and test using
npm run prepare
All changes must include appropriate tests.
Complex Expression Parser is open-sourced software licensed under the MIT license
FAQs
Parses and evaluates expressions over the complex numbers
We found that complex-expression-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.