Type a mathematical expression and get the result instantly, with trigonometry in radians or degrees, logarithms, factorials, constants and full operator precedence.
Write the expression the way you would on paper. The parser handles nested parentheses, unary minus, factorials and function calls with correct precedence, so 2 + 3 * 4 is 14 and -3^2 is -9, exactly as mathematical convention requires.
Reading 2 + 3 * 4 requires knowing that multiplication binds more tightly than addition, so the answer is 14 rather than 20. Every operator carries a precedence level and an associativity. Multiplication, division and the remainder operator sit above addition and subtraction; exponentiation sits above all of them and is right-associative, so 2^3^2 means 2^(3^2) and evaluates to 512, not 64.
Unary minus is the subtle case. Mathematical convention puts it below exponentiation, which is why -3^2 is -9: the exponent applies to 3 and the negation applies to the result. Spreadsheet software famously disagrees and returns 9, so if you have ever seen two tools give different answers to the same formula, this is usually why. This evaluator follows the mathematical convention.
Parentheses override all of it, and they are worth using freely. An expression that needs a precedence table to read is an expression that will be misread eventually.
Shunting-yard, briefly
The expression is first broken into tokens - numbers, names, operators and punctuation - and then reordered by Dijkstra's shunting-yard algorithm into postfix form, where operators follow their operands. 2 + 3 * 4 becomes 2 3 4 * +. Postfix needs no parentheses and no precedence rules, because the order of the tokens already encodes the structure, so a simple stack machine can evaluate it in a single pass.
The algorithm keeps two structures: an output list and an operator stack. Numbers go straight to the output; an operator first pops any stacked operator that binds at least as tightly before being pushed itself. Parentheses act as markers on the stack, and a closing parenthesis pops everything back to its partner. Function calls ride along as operators with an argument count that increases each time a comma is seen.
This is the same technique used inside spreadsheet engines and query planners. It runs in linear time, needs no recursion, and reports a malformed expression naturally: if the stack does not empty cleanly at the end, the input was unbalanced.
Floating point, honestly
Results are computed in IEEE 754 double precision, the same arithmetic every browser and most programming languages use. It stores numbers in binary, and a decimal fraction such as 0.1 has no exact binary representation, which is why 0.1 + 0.2 famously produces 0.30000000000000004 rather than 0.3.
Rounding the display to a set number of significant digits hides that noise without changing the underlying value, which is what the precision control does here. Setting it to 12 keeps the answer readable while leaving plenty of room before the 15 to 17 digits a double can actually distinguish.
Two limits are worth remembering. Integers stay exact only up to 2^53, so very large factorials and products drift; anything above 170! overflows to infinity outright. And subtracting two nearly equal numbers destroys precision - the leading digits cancel and only the noisy trailing digits survive - so a formula rearranged to avoid that subtraction will often be far more accurate than the obvious form.
FAQ
Why does -3^2 give -9 instead of 9?
Mathematical convention binds exponentiation more tightly than unary minus, so the square applies to 3 and the negation applies afterwards. Write (-3)^2 if you want 9, which is what spreadsheets assume by default.
Why is 0.1 + 0.2 not exactly 0.3?
Binary floating point cannot represent 0.1 exactly, so a tiny error survives the addition. Rounding to 12 significant digits displays 0.3 while the stored value keeps its full precision.
How do I switch trigonometry to degrees?
Set the angle unit to Degrees. Inputs to sin, cos and tan are then interpreted as degrees, and asin, acos and atan return degrees, with no manual pi/180 conversion.
Which constants are available?
pi, e, tau (2 pi), phi (the golden ratio) and inf for infinity. Names are case-insensitive, so PI and pi both work.
Can it handle factorials of large numbers?
Up to 170!, which is the largest factorial a double can hold. Beyond that the result overflows to infinity. Factorials also require a non-negative whole number.
Is the expression run through eval?
No. It is tokenised and converted to postfix by a dedicated parser, then evaluated on a small stack machine, so nothing you type is ever executed as JavaScript.