expression-evaluator
A math expression evaluator parses and computes any algebraic expression: 2 + 3 Γ (4 β 1), sin(Ο/4), log(100), xΒ² + 3x + 5 with x = 2. More flexible than a basic calculator because it supports operator precedence, parentheses, named functions (sin, cos, tan, log, ln, sqrt, abs, floor, ceil, round, exp, factorial), and variables you define. The ZTools Expression Evaluator uses a deterministic parser (no eval β safe), runs in the browser, and shows intermediate steps for debugging.
Use casesβ
Quick calculation with parenthesesβ
Evaluate (1 + 0.05)^10 Γ 1000 β a compound-interest formula. Faster than typing into a basic calc with manual order tracking.
Plug variables into a formulaβ
Define x = 5, evaluate xΒ² + 3x + 5. Result: 45. Re-evaluate with x = 10: result 135. No re-typing the formula.
Verify a physics formulaβ
KE = Β½mvΒ² with m = 2, v = 3 β 9. Calculator confirms.
Convert between expression stylesβ
A formula written with text (sin x cos y) gets re-rendered with explicit parens (sin(x) Γ cos(y)) for clarity.
How it worksβ
- Type expression β Text input accepting operators (+, β, Γ, Γ·, ^, %), functions (sin, cos, ...), and variables.
- Define variables β Optional table of (name, value) pairs. Used for substitution before evaluation.
- Pick angle unit β Radians (default for math) or degrees (for engineering / school).
- Evaluate β Parser tokenises β builds AST β evaluates. Result shown with configurable precision.
Examplesβ
Input: 2 + 3 Γ 4
Output: 14 (operator precedence: Γ before +).
Input: (2 + 3) Γ 4
Output: 20 (parentheses force order).
Input: sin(Ο/4)
Output: 0.7071... β equals β2/2. With degrees mode: sin(45Β°) = 0.7071.
Input: xΒ² + 3x + 5 with x=2
Output: 4 + 6 + 5 = 15.
Input: 5! Γ C(4,2)
Output: 120 Γ 6 = 720.
Frequently asked questionsβ
How is this safe vs eval()?
eval() runs arbitrary JavaScript. This evaluator parses tokens against a strict grammar β only known operators / functions / variables get evaluated. No code execution risk.
What functions are supported?
sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, log (base 10), ln (natural log), exp, sqrt, cbrt, abs, floor, ceil, round, factorial (!), C(n,r), P(n,r), max, min, mod.
Does it support symbolic math?
No β numeric only. For symbolic algebra (factor, integrate, solve), use Wolfram Alpha or SymPy.
Variable scope?
Variables persist within a session; clear or redefine as needed.
Precision?
JavaScript double-precision floats β about 15 significant digits.
Privacy?
All computation in browser.
Tipsβ
- Use parentheses generously β even when not strictly required, they improve readability and reduce errors.
- For engineering work, set angle unit to degrees before any trig calls β radians is the math default.
- Define commonly-used constants as variables (g = 9.81, c = 299792458) for repeated use.
- For symbolic results (e.g. Ο exactly, not 3.14159...), use Wolfram Alpha β this tool returns numeric only.
Try it nowβ
The full expression-evaluator runs in your browser at https://ztools.zaions.com/expression-evaluator β no signup, no upload, no data leaves your device.
Last updated: 2026-05-06 Β· Author: Ahsan Mahmood Β· Edit this page on GitHub