Use BIDMAS operator precedence for multi-operation expressions #32
Labels
No labels
blocked
duplicate
high priority
needs
approval
needs
criteria
needs
estimate
needs
tests
question
step
doing
step
review
step
testing
step
todo
step
uat
type
admin
type
alert
type
bug
type
change
type
defect
type
dependencies
type
development
type
documentation
type
epic
type
idea
type
incident
type
investigation
type
spike
type
story
type
tests
won't fix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
RabbitLabs/calculator#32
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Story Points: 3
Follow-up to #22 (multi-operation expressions).
Product decision (2026-10-05): BIDMAS / standard operator precedence is the only evaluation mode. The interim left-to-right behaviour is removed (not a toggle). No separate persistence or config is required.
User story
AS a calculator user
I WANT multi-operation expressions to follow standard BIDMAS precedence
SO THAT results match familiar maths rules (e.g.
5 + 2 * 6→17).Acceptance criteria
Default precedence (no toggle)
GIVEN I evaluate a multi-operation expression with
+,-,*, and/WHEN the expression is valid
THEN
*and/are applied before+and-, with left-to-right evaluation among operators of the same precedence (e.g.8 / 2 + 3→7,5 + 2 * 6→17).Left-to-right mode removed
GIVEN the previous left-to-right behaviour (e.g.
5 + 2 * 6→42)WHEN this change is complete
THEN that behaviour is no longer available and tests/docs do not describe it as supported.
Shared evaluation
GIVEN the same expression string
WHEN evaluated through CLI and GUI
THEN both surfaces return the same numeric result (shared
evaluatelogic).Operator scope
GIVEN expressions using only the operators the app already supports (
+,-,*,/)WHEN combined in one expression
THEN BIDMAS rules apply consistently.
Parentheses (out of scope here)
GIVEN parenthesised expressions are not yet supported in the app
WHEN this story is delivered
THEN behaviour matches criteria 1–4 without requiring
()parsing.WHEN parentheses support is added in a future story
THEN grouped sub-expressions must be evaluated before applying precedence to the rest (per @Vylpes).
Errors unchanged
GIVEN invalid expressions (malformed input, division by zero, etc.)
WHEN evaluation runs
THEN existing error handling and messages still apply (aligned with #22).
Subtasks
Notes
Planning — needs/criteria
Context from #22: multi-operation evaluation shipped as left-to-right (no operator precedence). This issue is to add an option to follow BIDMAS / standard operator precedence instead.
Before acceptance criteria can be finalized, I need decisions on the following:
--bidmas, env/config file, interactive REPL command, GUI toggle, or a combination? Should all surfaces stay in sync?)5 + 2 * 6→42(not17).*,/before+,-; left-to-right within the same precedence). Any need for parentheses in this story, or is that a separate follow-up?+,-,*,/as today, or should this story also cover anything else (modulo, powers, etc.)?Draft criteria (pending your answers)
GIVEN BIDMAS mode is disabled (default)
WHEN I evaluate a multi-operation expression
THEN evaluation matches current left-to-right behaviour (regression-safe).
GIVEN BIDMAS mode is enabled
WHEN I evaluate
5 + 2 * 6THEN the result is
17(not42).GIVEN BIDMAS mode is enabled
WHEN I evaluate
8 / 2 + 3THEN the result is
7((8 / 2) + 3).Please reply on this issue; once the above is decided I can lock the acceptance criteria and move to needs/estimate.
@Vylpes
@Smithy-bot wrote in #32 (comment):
Planning — needs/criteria → needs/estimate
Thanks @Vylpes — your answers are incorporated into the issue description.
Locked decisions
*/before+-, left-to-right within the same level.Acceptance criteria are in the issue body. Moving to needs/estimate for story points on the next planning pass.
Make an option to follow BIDMAS rulesto Use BIDMAS operator precedence for multi-operation expressionsPlanning — needs/estimate → needs/tests
Story point estimate for BIDMAS operator precedence (replacing left-to-right multi-op evaluation).
Acceptance criteria are specific enough to size. Breakdown:
evaluatelogic for operator precedence (*//before+/-, left-to-right within same precedence)Comparable to a focused change on top of #22 (which was sized at 5 for introducing multi-op evaluation). No toggle, config, or parentheses parsing in this story.
Setting Story Points: 3 on the issue body. Moving to needs/tests for QA scripts on the next planning pass.
Planning — needs/tests → needs/approval
QA scripts mapped to the acceptance criteria in the issue body. Run after implementation; automated unit/integration tests should cover the same cases where practical.
Preconditions
AC1 — Default BIDMAS precedence (no toggle)
5 + 2 * 6178 / 2 + 3710 - 4 / 28(10 - 2)3 * 2 + 5 * 216(left-to-right among same precedence:6 + 10)AC2 — Left-to-right mode removed
5 + 2 * 617, not42AC3 — Shared evaluation (CLI + GUI)
1 + 2 * 3,20 / 4 - 1,2 + 3 * 4 - 5— run on CLI and GUIevaluate(or equivalent) pathAC4 — Operator scope (
+,-,*,/)24 / 4 / 23(left-to-right within/)6 + 3 * 2 - 4 / 210(6 + 6 - 2)AC5 — Parentheses out of scope
()are not supported today: enter(2 + 3) * 4on CLI/GUIAC6 — Errors unchanged
1 + * 2, trailing operator)1 + 2 / 0)3 + 4,10 / 2)Sign-off checklist
Moving to needs/approval for your review before implementation. @Vylpes