Apply percent immediately for all pending operators - #1
Conversation
6c654ed to
906a504
Compare
When % follows any pending operator, show the running total with the percent applied as soon as % is pressed: - 200 + 10% displays 220 - 200 − 10% displays 180 - 200 × 10% displays 20 - 200 ÷ 10% displays 2000 The evaluated expression is preserved as "200 + 10%" instead of the intermediate "200 + 20", making the calculation easier to read. On its own, x% still divides by 100.
70ee295 to
6528d54
Compare
016e888 to
6528d54
Compare
Applying the percent by collapsing everything left of the pending operator into a single base loses precedence for × and ÷: `2 + 3 × 10 %` evaluated (2 + 3) × 0.1 and showed 0.5 where every calculator, and this one before the change, shows 2.3. `10 + 2 × 3 %` showed 0.36 instead of 10.06. Resolving the percent into the operand the pending operator is waiting for and then evaluating the whole token list keeps the answer right while still showing it immediately, which is what the change was after. The same rewrite gives the failure paths an answer. A non-finite total used to return with nothing changed, so `200 ÷ 0 %` left the percent key silently dead; it now errors the way `=` does on the same expression. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Reviewed on a disposable VM; The unification lost operator precedence for A smaller one alongside it: a non-finite total returned with nothing changed, so Pushed 18e23c1 for both. It keeps your immediate-result semantics and the shape of the code you wrote, and changes only how the total is reached: resolve the percent into the operand the pending operator is waiting for — a percentage of the running total for One thing left for the maintainer rather than for you: Worth knowing: #7 carries 6528d54 as-is, so it still has the precedence bug until this branch is merged or rebased into it. |
Summary
+,−,×,÷).Test plan
./bin/testpasses./bin/buildsucceeds