Math Expression Evaluator
Everyday
A safe calculator for expressions you'd write on paper: `(1 + 2) * 3.14`, `sqrt(2)`, `sin(pi / 4)`, `log10(1000)`, `2^10`. Operators `+ - * / % ^` work; functions and constants are pulled from a fixed allowlist that maps to `Math.*` — `sin/cos/tan/asin/acos/atan/atan2`, `sinh/cosh/tanh`, `sqrt/cbrt/abs/sign/floor/ceil/round/trunc`, `log/log2/log10/ln/exp/pow`, `min/max/hypot`, plus `pi/e/tau`. Identifiers outside this list are rejected, so the input can't reach into the page or the JavaScript runtime.
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 use `pow(x, y)` or `x^y`.
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
Loan / Mortgage Calculator
Calculate the monthly payment, total interest, and full amortization schedule for any fixed-rate loan.
Compound Interest Calculator
Project how a starting balance grows with regular contributions, your interest rate, and your compounding frequency.
Age Calculator
Calculate exact age in years, months, days — and find your next birthday.
BMI Calculator
Calculate Body Mass Index from height and weight, with a healthy range.
Tip Calculator
Calculate the tip and split the total bill between people.
Percentage Calculator
Work out percentages, what-percent, and percent change in one place.