Math Expression Evaluator
Evaluate arithmetic expressions with the usual math functions — sqrt, sin, log, pow, min/max, and constants pi, e, tau.
Result
8
Safe by construction: identifiers must come from the allowlist (sin, cos, tan, sqrt, log, ln, exp, pi, e, tau, min, max, hypot, …). No variables, no string literals, no semicolons.
How to use
- Type an expression — operators, parentheses, decimals, and the allowed names.
- The result updates live; copy it if you need to paste elsewhere.
^is exponent (like in math, not bitwise XOR). For powers of variables usepow(x, y)orx^y.
About this tool
ShowHide
A calculator for expressions written the way you would on paper: (1 + 2) * 3.14, sqrt(2), sin(pi / 4), 2^10. The operators + - * / % ^ work, and functions and constants come from a fixed allow-list — the trigonometric family, sqrt, cbrt, abs, sign, the rounding functions, log, log2, log10, ln, exp, pow, min, max, hypot, and pi, e, tau. Any identifier outside that list is refused before evaluation, so nothing typed into the box can reach the page or the JavaScript runtime.
Two conventions differ from JavaScript itself and are worth knowing. ^ means exponentiation here rather than bitwise XOR, and it is right-associative in the mathematical way, so 2^3^2 is 2^9, that is 512, not 8^2. And log is the natural logarithm, following JavaScript's Math.log rather than the base-ten log key on a pocket calculator — log(100) is about 4.6, and log10(100) is the 2 you probably wanted. ln is provided as a synonym so the intent can be written explicitly either way.
Everything runs in double-precision floating point, which sets the accuracy ceiling. 0.1 + 0.2 produces 0.30000000000000004 here exactly as it does in every other language that uses the same representation. sin(pi) returns about 1.2 × 10^-16 rather than zero — not because the sine is wrong, but because pi itself is the nearest representable double to π, and the true sine of that slightly-off number is genuinely not zero. Results beyond fifteen or sixteen significant digits are noise, and an expression that subtracts two nearly equal large numbers will lose most of its precision in one step.
Angles are radians throughout, as they are in Math. To work in degrees, multiply by pi / 180 on the way in — sin(30 * pi / 180) gives the 0.5 you expect, while sin(30) is a perfectly valid answer to a different question.
Frequently asked questions
Is eval being used under the hood?
A new Function(...) call is used, but only after the input is parsed for identifiers and matched against an allowlist (sin, sqrt, pi, …). Anything else — document, window, fetch, string literals, semicolons — is rejected before execution, so the expression has no way to reach outside Math.*.
What angle unit do sin and friends use?
Radians, matching JavaScript's Math.sin. Use pi to express common angles — sin(pi / 2) is 1, cos(pi) is -1. To convert degrees, multiply by pi / 180 before passing in.
Why does my huge calculation lose precision?
JavaScript numbers are IEEE 754 doubles — about 15 significant decimal digits. 0.1 + 0.2 gives 0.30000000000000004. For higher precision (financial decimals, factorials past 20!, etc.) use a dedicated arbitrary-precision tool or library.
What about variables or multi-line scripts?
Not supported on purpose — keeping the surface area small is what makes this safe to evaluate. For programmable math, use a Jupyter notebook or a desktop calculator.
Related tools
XPath Tester
Run an XPath expression against XML or HTML in your browser and see every node it matches, with namespace prefixes and parse errors reported.
Developer
Regex Tester
Test JavaScript regular expressions live with highlighted matches and replace preview.
Developer
Prime Factorization · GCD · LCM
Factor an integer into primes, list all divisors, and compute GCD and LCM of two numbers. Handles values up to ~10¹².
Math & Statistics
Combinations & Permutations Calculator
Compute nCr and nPr, with and without repetition, plus factorials — exact arbitrary-precision integers for probability, lottery odds and combinatorics.
Math & Statistics
Right Triangle Calculator
Solve a right triangle from any two sides — get the third side, both acute angles, area and perimeter using the Pythagorean theorem.
Math & Statistics
Slope & Line Calculator
From two points, get the slope, the line equation y = mx + b, the distance, midpoint, angle of inclination, and rise/run.
Math & Statistics
Scientific Notation Converter
Convert any number to scientific, engineering and E-notation, with significant-figure rounding, an expanded decimal and the order of magnitude.
Convert