Exponent Calculator
Any base to any power, negative and fractional included.
A full scientific calculator with trigonometry, logarithms, powers, roots, factorials and constants — parsed with a hand-written tokeniser and shunting-yard algorithm, never with eval.
About precision. Results are computed in double-precision floating point, which is exact for whole numbers up to about sixteen digits and very slightly approximate beyond that. Figures are rounded for display, so a long chain of calculations can differ from a hand-worked answer in the last decimal place. Where an exact fraction or radical exists, this page shows it alongside the decimal.
This is a full expression calculator rather than a button-at-a-time one: you write the whole calculation and it is parsed as a unit, so operator precedence and brackets behave the way they do on paper. Nothing you type is ever executed as code.
Errors are reported in plain language and point at the character that caused them. An unclosed bracket says so; an unknown function name is quoted back to you.
The parser is worth describing, because how a calculator reads an expression determines what it answers.
| Symbol | Meaning | Unit | Typical range |
|---|---|---|---|
Tokens | Numbers, operators, functions, brackets | — | — |
Precedence | Which operator binds more tightly | level | 1 – 4 |
RPN | Reverse Polish Notation, an operator stack order | — | — |
Angle mode | Degrees or radians for trigonometry | — | — |
Length | Maximum expression length | characters | 400 |
The shunting-yard algorithm was published by Edsger Dijkstra in 1961 and is still the standard way to turn infix notation into something a machine can evaluate. It reads left to right once, pushing operators onto a stack and popping them when a lower-precedence one arrives — which is why it needs no backtracking and runs in linear time.
sqrt(1728) + 5! tokenises into a function, a number, an operator and a factorial. The square root of 1,728 is 41.5692193817 and 5! is 120, so the result is 161.5692193817. Try replacing the factorial with 5!! and the parser will tell you a factorial sign has no number in front of it, rather than producing something arbitrary.
First, 2^3^2 = 512. Powers associate to the right, so it means 2^(3^2) = 2^9, not (2^3)^2 = 64. Second, −3^2 = −9. The power binds more tightly than the minus sign, so it is −(3^2) rather than (−3)^2. Both follow the standard mathematical conventions, and both differ from what some spreadsheet software does — which is worth knowing before trusting either.
Every operator and function, in precedence order.
| Level | Symbols | Associativity | Note |
|---|---|---|---|
| 4 — highest | ^ | Right | 2^3^2 is 2^(3^2) = 512 |
| 3 | Unary minus | Right | Binds looser than a power, so −3^2 = −9 |
| 2 | × ÷ mod | Left | mod is the remainder, not a percentage |
| 1 — lowest | + − | Left | Evaluated last unless brackets say otherwise |
| Functions | sin cos tan ln log sqrt … | — | Always take brackets |
The one entry worth reading twice is unary minus. Placing it below the power operator is the standard mathematical convention and it means −3² is negative nine, because the squaring happens first. If you want the square of negative three, write (−3)^2 and the brackets settle it.
The angle mode catches people more often than anything else on the page. In degrees, sin(30) is exactly 0.5. In radians, sin(30) is −0.988, because thirty radians is about 1,719 degrees and lands somewhere quite different on the circle. Neither answer is wrong; they answer different questions, and the toggle is above the field for that reason.
Everything is computed in double-precision floating point, which is exact for whole numbers up to about sixteen digits. Beyond that, and for any decimal that cannot be written exactly in binary, results are very slightly approximate — which is why 0.1 + 0.2 comes to 0.30000000000000004 in almost every programming language, including the one this page is written in. The display rounds to ten decimal places, which hides that particular artefact without pretending it is not there.
Four things this calculator deliberately does not do.
It does not use eval. The obvious way to build an expression calculator in a browser is to hand the text straight to the language's own evaluator. It is also the way to let any string that reaches the field run as code. Writing a parser is more work and it means an expression is never anything but data.
It does not do symbolic algebra. There are no variables, no solving for x and no simplification of expressions. Every input evaluates to a single number, which is a deliberate limit rather than an omission.
It does not handle complex numbers. The square root of a negative number returns an error rather than an imaginary result, and an even root of a negative does the same. Anything requiring the complex plane needs a different tool.
It does not keep arbitrary precision. Factorials above 170 overflow and are refused rather than silently returning infinity. Very large integers lose exactness past sixteen digits, which is a property of the number format rather than of the parser.
One design decision worth explaining. The keypad inserts text at the cursor rather than driving a hidden state machine, which means you can freely mix typing and tapping, edit the middle of an expression, and see exactly what will be evaluated before it is. Traditional calculators hide their working in an internal register and that is where most user errors come from — a pending operation you have forgotten about, silently applied when you press equals.
Here the expression is the whole state. If it looks right, it is right, and if it is wrong you can see the wrong part and fix it rather than starting again.
Within those limits it is a complete scientific calculator, and the specialised pages elsewhere on the site do the same arithmetic with explanation attached — the exponent calculator for powers, the square root calculator for roots and radical form, and the standard deviation calculator for anything involving a dataset rather than a single expression.
It tokenises the text, reorders it into Reverse Polish Notation with the shunting-yard algorithm, then evaluates it on a stack. Nothing is passed to eval or any other code-execution route.
Because multiplication binds more tightly than addition, so the multiplication happens first. Writing (2 + 3) × 4 gives 20 instead.
Powers associate to the right, so it means 2^(3^2) = 2^9 = 512. Reading it left to right as (2^3)^2 would give 64, which is not the mathematical convention.
The power binds more tightly than the minus sign, so it is −(3²) = −9. For the square of negative three, write (−3)^2 and the brackets settle it.
In degrees sin(30) is exactly 0.5; in radians it is −0.988, because thirty radians is about 1,719 degrees. Set the toggle before doing any trigonometry.
sin, cos, tan, their inverses, the hyperbolic versions, ln, log, sqrt, cbrt, abs, exp, floor, ceil, round and sign. Constants are pi, e, tau and phi.
A trailing exclamation mark: 5! is 120. It needs a whole number of zero or more, and anything above 170 is refused because the result cannot be represented.
It is a remainder operator, not a percentage. 10 % 3 gives 1. For percentage work, the percentage calculator is the right tool.
No. It returns an error rather than an imaginary result, because complex numbers are outside what this calculator covers.
Because binary floating point cannot represent those decimals exactly. The true result is 0.30000000000000004, which the display rounds away — an artefact of the number format rather than of the parser.
Six tools that pick up where this one leaves off.
Any base to any power, negative and fractional included.
MathSquare, cube and nth roots with simplified radical form.
MathThree percentage questions in one tool, with the working shown.
MathSpread, variance and the sample-versus-population choice made explicit.
MathEight shapes, any unit, with the formula for each.
MathSingle, combined and at-least-once probabilities without the algebra.
MathCookies. We use cookies for site functionality and to serve ads via Google AdSense. Nothing you type into a calculator is ever stored or sent anywhere. Read our Cookie Policy.