Fix Float32#abs for signed zeros#15814
Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom May 26, 2025
Merged
Conversation
straight-shoota
approved these changes
May 22, 2025
1 task
straight-shoota
added a commit
that referenced
this pull request
Feb 12, 2026
This fixes a regression from #15814 which unintentionally changed the return type of `Float32#abs` to `Float64`. Previously, it returned `Float32`. `Math.copysign(self, 1)` falls back to the overload without restrictions which converts both arguments to `Float64` and thus returns `Float64`. This patch fixes that by explicitly targeting the `Math.copysign(Float32, Float32)` overload for `Float32#abs`. `Float64#abs` is not broken, but still applies an unnecessary integer-to-float conversion when we should be using a float right away. I discovered this type mismatch while researching #13389
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.
Like #12424, but for
Float32.