feat(eval): fold ^ before multiply - #9
Open
JustNak wants to merge 1 commit into
Open
Conversation
The keyboard sends ^. evaluateTokens walks it right-to-left so 2 ^ 3 ^ 2 is 512, then × and ÷, then + and −. 0^0 and a negative base with a non-integer exponent return Error. The keypad is unchanged.
Greptile SummaryThe PR adds keyboard-entered exponentiation with right-associative precedence while retaining the existing alternating-token evaluator design.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/backend.cpp | Adds ^ to operator state handling and implements guarded, right-associative power folding before the existing arithmetic passes. |
| src/Main.qml | Extends the focused keyboard handler to forward the ^ character without changing the on-screen keypad. |
| tests/tst_omacalc.cpp | Covers exponentiation precedence, associativity, chaining, invalid domains, and percent behavior. |
| README.md | Documents keyboard exponentiation, evaluation order, and percent semantics with a pending power operator. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Keyboard input: ^] --> B[Backend::pressKey]
B --> C[pressOperator]
C --> D[Alternating expression tokens]
D --> E[Fold powers right-to-left]
E --> F[Fold multiplication and division left-to-right]
F --> G[Fold addition and subtraction]
G --> H[Formatted result or Error]
Reviews (2): Last reviewed commit: "feat(eval): fold ^ before multiply" | Re-trigger Greptile
Author
|
Closing this in favor of reviewing on the fork first: JustNak#1 |
|
I've been wanting this too. Had the same idea, keep as keyboard only. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The keypad is four-function. Keyboard users still expect Shift+6 to raise a number to a power.
2 ^ 2should be 4.Scope
Backend::evaluateTokensfolds^right-to-left, then×÷, then+−.pressKeyandisOperatortreat^as an operator, so dangling-operator replacement and chaining keep working.Main.qmlaccepts^from the keyboard. The 4×5 keypad is unchanged.0 ^ 0and a negative base with a non-integer exponent return Error.^is x÷100, same as×and÷.README.mddocuments the key and the fold order.calculatesPowers,percentOfRunningTotal, andevaluatesTokens.Tradeoffs
^, so2 ^ 3 ^ 2is 512. A left-associative fold would print 64 and surprise anyone who writes math.Blast Radius
Keyboard
^is new input. Existing+−×÷paths still run after the power pass. Percent of running total still applies only to pending+or−.Verification
./bin/testin this tree. 20 passed, 0 failed, including2 ^ 2, mixed precedence, right-associativity,0 ^ 0,(-2) ^ 0.5, and2 ^ 10%../bin/buildproducedbuild/omacalc.^.pressKey("^")is what the tests drive.