Operator precedence, and the answers calculators disagree about
Why two calculators give different answers to the same expression, what implicit multiplication does to precedence, and the floating point results that look wrong and are not.
Last reviewed · 1,291 words
In short
- 6 ÷ 2(1+2) has no single correct answer. It depends on whether implicit multiplication binds tighter than division, and conventions differ.
- 0.1 + 0.2 is 0.30000000000000004 in binary floating point. That is correct arithmetic in base 2, not a bug.
- Trigonometric functions need the right angle mode. sin(30) is 0.5 in degrees and −0.988 in radians.
- −2² is −4 under standard precedence, because exponentiation binds tighter than the unary minus.
- Calculators differ on ambiguous input. Write parentheses and the ambiguity disappears.
Most disagreements between calculators come from the same three places: precedence, angle mode and floating point. None of them is a bug.
Standard precedence
Operations are evaluated in a fixed order:
- Parentheses
- Exponents
- Multiplication and division, left to right
- Addition and subtraction, left to right
The mnemonics — BODMAS, BIDMAS, PEMDAS — all describe the same order and all mislead in the same way, by implying that multiplication comes before division and addition before subtraction. They do not. Multiplication and division have equal precedence and are evaluated left to right, and the same for addition and subtraction.
8 ÷ 4 × 2 is (8 ÷ 4) × 2 = 4, not 8 ÷ (4 × 2) = 1.
10 − 3 + 2 is (10 − 3) + 2 = 9, not 10 − (3 + 2) = 5.
The expression with two answers
6 ÷ 2(1+2) produces 9 on some calculators and 1 on others, and both are defensible.
Reading it as 9: resolve the parentheses to get 6 ÷ 2 × 3, then evaluate left to right: 3 × 3 = 9.
Reading it as 1: treat 2(1+2) as a single term, because implicit multiplication by juxtaposition binds more tightly than division. Then 6 ÷ 6 = 1.
The second convention is standard in much of mathematics and physics, where 1/2x universally means 1/(2x) rather than x/2. The first is what a strict left-to-right parser does.
Casio calculators changed behaviour between generations. Texas Instruments and Casio have disagreed. Wolfram Alpha and most programming languages give 9, because they parse implicit multiplication at the same precedence as explicit.
There is no correct answer, because the notation is ambiguous. The resolution is not to argue about it but to write 6 ÷ (2 × (1+2)) or (6 ÷ 2) × (1+2) and remove the ambiguity. Any expression that starts an argument should be rewritten.
The unary minus
−2² is −4, not 4.
Exponentiation binds tighter than the unary minus, so the expression is −(2²). To square negative two you must write (−2)², which is 4.
Spreadsheets disagree. Excel evaluates =-2^2 as 4, treating the minus as part of the number literal — a documented deviation from standard mathematical convention that has caused real errors in financial models.
This is worth knowing because it is silent. Both answers look plausible, and nothing warns you which convention the tool applied.
Angle modes
Trigonometric functions take an angle, and there are three units.
| Mode | Full circle | Where used |
|---|---|---|
| Degrees | 360 | Everyday geometry, navigation, engineering |
| Radians | 2π ≈ 6.283 | Calculus, physics, all programming languages |
| Gradians | 400 | Surveying, rarely elsewhere |
sin(30) is 0.5 in degrees and −0.988 in radians. Both are correct answers to different questions.
This is the most common source of a wrong answer in practice, and it is invisible — the result looks like a number, not like an error. Check the mode indicator before trusting a trigonometric result, particularly on a calculator someone else used last.
Every programming language uses radians. Converting is radians = degrees × π ÷ 180.
Floating point
0.1 + 0.2 gives 0.30000000000000004 on almost every calculator and in almost every programming language.
This is not a bug. Binary floating point cannot represent 0.1 exactly, for the same reason decimal cannot represent one third exactly. 0.1 in binary is a repeating fraction, so it is stored as the nearest representable value, and the tiny error surfaces when two such values are added.
The consequences worth knowing:
Never compare floats for exact equality. 0.1 + 0.2 === 0.3 is false. Compare the absolute difference against a small tolerance instead.
Never use floating point for money. Store amounts in the smallest unit as integers — paise, cents — or use a decimal type. Accumulated rounding errors in a financial system are a real and expensive class of bug.
Errors accumulate. Summing a million small floats drifts measurably from the true total.
Some calculators display 0.3 by rounding for presentation, which hides the issue and does not remove it. This one shows what the arithmetic actually produced, on the grounds that the surprise is better encountered here than in production code.
Notation and constants
Scientific notation. 1.5e6 is 1,500,000 and 2.3e-4 is 0.00023. Calculators switch to it automatically for very large or very small results.
Precision limits. Standard 64-bit floating point holds about 15 to 17 significant decimal digits. Beyond that, digits are noise. A result displayed to twenty decimal places is showing more precision than exists.
Constants. π ≈ 3.14159265358979 and e ≈ 2.71828182845905, both to the precision the format supports.
Factorial grows extraordinarily fast: 20! is about 2.4 × 10¹⁸ and 171! exceeds what a double can represent, returning infinity.
Logarithms need care about the base. log means base 10 on most calculators and base e in most programming languages. ln is unambiguously natural log. Where a calculator writes only log, check which it means before relying on it.
Where errors actually come from
Wrong angle mode, by a wide margin the most common.
Missing parentheses around a numerator or denominator. 1 ÷ 2 + 3 is 3.5; 1 ÷ (2 + 3) is 0.2.
Percentage keys, which behave inconsistently across calculators. 200 + 10% gives 220 on some and 200.1 on others, depending on whether the percentage is taken of the preceding number or treated as 0.1.
Chained equals, where pressing equals repeatedly repeats the last operation on some models and does nothing on others.
Reading the display wrongly when it is in scientific notation, and losing a factor of a thousand.
The habit that prevents most of these: write the expression with explicit parentheses, then check the order of magnitude of the answer against a rough mental estimate. A result that is a thousand times off is much easier to catch than one that is 2% off.
Memory and the running total
Most scientific calculators carry two independent stores and confusing them produces wrong answers silently.
M+ and M− add to and subtract from a memory register. MR recalls it and MC clears it. The register persists across calculations, which is what makes it useful and what makes a stale value dangerous — a forgotten M+ from an earlier problem contaminates the next one.
Ans holds the last result and is a different thing. Starting an expression
with an operator implicitly uses it, so typing × 2 after a result doubles it.
The practical habit is to clear memory before starting anything new, and to be sceptical of a memory recall that produces a number you cannot account for.
Reading a result critically
A calculator answers the question you typed, which is frequently not the question you meant. Three checks catch most of it.
Estimate first. Round every input to one significant figure and do the sum in
your head. 847 × 1.19 is roughly 800 × 1 — so a result near 1,000 is
plausible and one near 100 or 10,000 is not. This single habit catches almost
every misplaced decimal and every mistyped digit.
Check the units. A result in the wrong unit is a wrong result, and the calculator has no idea what your numbers represent.
Check the sign. A negative where a positive belongs usually means an operand was entered in the wrong order — subtraction and division are not commutative, and reversing them is the most common transcription error.
Re-enter and repeat. For anything consequential, do the calculation twice, ideally entering the expression differently the second time. Two independent routes to the same answer is worth more than staring at one.
What this tool assumes
- Standard precedence with left-to-right evaluation for equal-precedence operators.
- Implicit multiplication is treated at the same precedence as explicit multiplication, so
6/2(1+2)gives 9. Use parentheses if you mean otherwise. - Angle mode as selected, shown on the display; check it before any trigonometric calculation.
- IEEE 754 double-precision floating point, with about 15 significant digits and the rounding behaviour that implies.
- Everything runs in your browser. Nothing you calculate is sent anywhere.