Skip to content
AZ Tools

Math Expression Evaluator

Evaluate arithmetic expressions with the usual math functions — sqrt, sin, log, pow, min/max, and constants pi, e, tau.

Try:

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

  1. Type an expression — operators, parentheses, decimals, and the allowed names.
  2. The result updates live; copy it if you need to paste elsewhere.
  3. ^ is exponent (like in math, not bitwise XOR). For powers of variables use pow(x, y) or x^y.

About this tool

Show

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