fix: exclude precision-losing integer-to-float conversions from CastExpr::check_bigger_cast (#23808)#23809
Open
getChan wants to merge 1 commit into
Open
fix: exclude precision-losing integer-to-float conversions from CastExpr::check_bigger_cast (#23808)#23809getChan wants to merge 1 commit into
getChan wants to merge 1 commit into
Conversation
…xpr::check_bigger_cast (apache#23808)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #23809 +/- ##
=======================================
Coverage ? 80.71%
=======================================
Files ? 1089
Lines ? 368916
Branches ? 368916
=======================================
Hits ? 297778
Misses ? 53379
Partials ? 17759 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Which issue does this PR close?
Rationale for this change
ref. #23807
CastExpr::check_bigger_castis used to determine whether a cast is a widening (order-preserving) conversion. Currently, it classifiesInt32 -> Float32,UInt32 -> Float32,Int64 -> Float64, andUInt64 -> Float64as widening casts.However, integer-to-float conversions for 32-bit and 64-bit integers lose precision when values exceed the mantissa bit limit (24 bits for
Float32, 53 bits forFloat64). For example:16_777_216_i32 as f32 == 16_777_217_i32 as f32(both yield 16777216.0f32).Because distinct integer inputs can collapse to the same float output, these casts are not strictly 1-to-1 (injective) and can break suffix sort key ordering in multi-column ordering analysis (e.g.
[CAST(a AS Float32), b]).What changes are included in this PR?
CastExpr::check_bigger_castto exclude precision-losing integer-to-float conversions (Int32/UInt32 -> Float32andInt64/UInt64 -> Float64).test_check_bigger_cast_precision_lossto verify precision-losing casts returnfalsewhile exact conversions (Int16 -> Float32,Int32 -> Float64, etc.) continue to returntrue.Are these changes tested?
Yes, new unit test
test_check_bigger_cast_precision_lossincast.rs.Are there any user-facing changes?
No breaking API changes. Internal optimizer behavior fix.