fix: preserve operand width in DecimalValue checked arithmetic#7380
Open
abnobdoss wants to merge 1 commit intovortex-data:developfrom
Open
fix: preserve operand width in DecimalValue checked arithmetic#7380abnobdoss wants to merge 1 commit intovortex-data:developfrom
abnobdoss wants to merge 1 commit intovortex-data:developfrom
Conversation
…thmetic (vortex-data#7022) Signed-off-by: Abanoub Doss <abanoub.doss@gmail.com>
Contributor
|
I256 is not the maximum of the inputs. I would accept a PR doing this |
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.
Summary
Closes: #7022
DecimalValue::checked_add/sub/mul/divunconditionally upcast both operands toi256and returnedDecimalValue::I256, producing unnecessarily wide scalars even when both inputs were narrow (e.g.I32 + I32 → I256).Operate at
max(self, other)width instead, matching the pattern inaggregate_fn/fns/sum/decimal.rs. The oldchecked_binary_ophelper was replaced with a local macro so each op dispatches with its own trait.AI disclosure: Analysis, implementation, and tests were done with Claude Code under my direction and review.
API Changes
No public API signature changes (verified via
./scripts/public-api.sh).Overflow is now caught at the target width rather than silently widening (e.g.
I8(i8::MAX) + I8(1)now returnsNoneinstead ofI256(128)). This felt like the most faithful reading of the issue, but I'd appreciate a sanity check that returningNoneon target-width overflow is the desired semantics rather than, say, promoting to the next wider variant. No in-tree caller depends on the old behavior:sum/mod.rspre-widens the accumulator by +10 precision,decimal/scalar.rs::checked_binary_numericrequires both operands to share the same width, andsum/constant.rsusesI128as the multiplier.Testing
test_decimal_value_checked_*to assert the correct variant.i8::MIN / -1).