A real expression parser: type the whole calculation, precedence handled
Basic calculators make you choreograph keystrokes around their limits; a scientific calculator takes the expression as written. This one runs a proper parser with documented precedence: parentheses, powers (right-associative, as mathematics writes them), multiplication before addition, factorials, roots, logarithms and the trig family in degrees or radians, with the constants pi, e and tau, an Ans key for the last answer, a memory register, and a history of your recent calculations. Domain mistakes get explanations, not NaN: divide by zero, take the root of a negative, or unbalance a parenthesis and the page says which rule was broken. Nothing you type is ever executed as code: the parser reads numbers and operators, and nothing else exists to it.
Disclaimer: This calculator gives estimates for general information only. It is not financial, medical or other professional advice. Results are floating-point values shown to twelve significant digits; exact symbolic answers belong to the algebra calculators linked below.
What this calculator does
The heart of the page is a tokenizer and a recursive-descent parser, the same architecture real calculators and programming languages use: your text becomes tokens, tokens become a tree according to the precedence grammar, and the tree is evaluated with domain checks at every operation. That buys correctness where it is commonly lost: 2^3^2 evaluates as 2^(3^2) = 512 because exponentiation associates to the right; −3^2 reads as −(3^2) = −9, because unary minus applies after the power, matching standard mathematical typesetting; and 3 + 4 × 2^3 is 35, not 56, because multiplication waits for the power and precedes the addition. Factorials extend to non-integers through the gamma function, so (0.5)! returns √π/2’s value 0.886227, which surprises pleasantly the first time.
How to use it
- Type naturally, with the keypad as an aid. Function names are sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, ln, log (base 10), log2, sqrt, cbrt, abs, exp; constants pi, e, tau; operators + − * / ^ and postfix ! and %, plus “mod” for remainders: 17 mod 5 = 2.
- Degrees versus radians is a mode, not a conversion. The selector governs both directions (trig inputs and inverse-trig outputs); the classic wrong answer sin(30) = −0.988 is radians doing their job in the wrong room.
- Ans and memory chain calculations. Ans recalls the last result inside a new expression; M+ adds the display to memory, MR recalls it, MC clears it, and the register survives between calculations on this page.
- Percent is a postfix divide-by-hundred. 250 + 10% evaluates as 250.1 under this grammar (the % scales the 10, it does not mark up the 250), which this text states openly because phone calculators made the other convention famous: read the method before trusting a percentage.
The method
- Precedence, tightest first: postfix ! and %; powers ^ (right-associative); unary minus; ×, ÷, mod; +, −. Parentheses override at every level, and implicit multiplication is NOT assumed: write 2*pi, not 2pi, so the grammar stays unambiguous.
- Functions evaluate on their parenthesised argument; trig follows the angle mode; ln is natural, log is base 10, log2 base 2. Factorial is exact for whole numbers to 170 and the gamma function (Lanczos approximation) beyond and between.
- Domain checks at every step: division and mod by zero, roots and logarithms outside their domains, factorial overflow, unbalanced parentheses and unknown words each produce their specific explanation.
- Display: twelve significant digits, trailing zeroes trimmed; integers print whole within safe range, very large and small magnitudes use exponent notation.
Worked examples
3 + 4 * 2^(1+2) = 35. Parentheses first: 1+2 = 3; power: 2^3 = 8; multiplication: 4 × 8 = 32; addition: 3 + 32 = 35. A left-to-right machine says 56 or worse, which is why precedence exists and why the parser, not keystroke order, is in charge here.
sin(30) in degrees = 0.5; log(1000) = 3; 5! = 120. Three landmarks every scientific calculator must land: the special-angle value, the base-10 logarithm of a power of ten, and the factorial ladder 5 × 4 × 3 × 2 × 1. And 2^3^2 = 512, the associativity test: entered in the examples so the convention can be verified rather than trusted.
Reading your results
Read the history as your audit trail: each line keeps the expression, the mode and the result, so a long chain can be re-walked when a figure looks wrong two steps later. Read exponent-notation results by their scale (1.23e6 is about 1.23 million) and read domain errors as the calculator refusing politely: each names the rule, which is usually the actual question the user was asking. Ans appearing in the history marks chained work; a surprising result after an Ans line is most often yesterday’s answer entering today’s expression exactly as designed.
Limitations
- Floating point is floating point. 0.1 + 0.2 returns 0.30000000000000004 at full precision and 0.3 at the displayed twelve digits; money and exact rational work belong to the fraction and algebra tools, and this page says so rather than rounding silently.
- No implicit multiplication and no variables besides Ans and the memory. Expressions are numeric; symbolic algebra (simplifying, solving) lives on the equation and factoring pages linked below.
- Factorials cap at 170! (about 7.26 × 10^306); beyond that the gamma evaluation overflows double precision and the page reports overflow instead of printing infinity as a number.
- The % convention differs from phone calculators. Here it is a plain postfix scaling; markup and discount questions belong to the percentage and discount calculators, which model those flows explicitly.
Frequently asked questions
Why does 2^3^2 equal 512 and not 64?
Because exponentiation is right-associative in mathematics: a tower of powers is read from the top down, 2^(3^2) = 2^9 = 512. Read left to right it would be (2^3)^2 = 64, which is a different expression wearing the same keystrokes, and the convention exists precisely to disambiguate them. The parser implements the mathematical convention and the worked example prints it, so the behaviour is checkable rather than a matter of faith in this page.
What is the difference between ln and log?
ln is the natural logarithm, base e ≈ 2.71828, the logarithm of calculus and continuous growth; log on scientific calculators is base 10, the logarithm of orders of magnitude, so log(1000) = 3. The change-of-base identity connects everything: log base b of x is ln(x)/ln(b), and log2 is offered directly because computing made it a citizen. Confusing ln with log costs a factor of about 2.303, and the keypad labels them in full to make the confusion harder.
Why did sin(30) give a negative number?
Almost certainly the angle mode: in radians, 30 radians is four and three-quarter turns, landing in a negative-sine region, and sin(30 rad) ≈ −0.988. In degrees the same keystrokes give the schoolbook 0.5. The mode selector sits beside the input and the history records which mode each result used, because this single toggle is responsible for more wrong answers than every other calculator fault combined.
Can this calculator do fractions exactly?
No: it computes in decimal floating point like every scientific calculator, so 1/3 is 0.333333333333 at display precision. Exact rational arithmetic is the Fraction Calculator’s entire design (linked in the Math hub), and expressions mixing the two needs should be split: evaluate the scientific part here, carry exact fractions there. Knowing which instrument a question belongs to is most of numeracy, and the hub exists to make the choice easy.
Related calculators
Method: tokenised recursive-descent evaluation with documented precedence and right-associative powers, domain-checked operations, gamma-based factorials, degree and radian modes, Ans and memory registers, and a session history. Last reviewed: 15 October 2026.
