Skip to content

Fix Float32#abs to return Float32#16655

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
straight-shoota:fix/float.abs
Feb 12, 2026
Merged

Fix Float32#abs to return Float32#16655
straight-shoota merged 2 commits intocrystal-lang:masterfrom
straight-shoota:fix/float.abs

Conversation

@straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Feb 11, 2026

This is 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

@straight-shoota straight-shoota self-assigned this Feb 11, 2026
@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric kind:regression Something that used to correctly work but no longer works labels Feb 11, 2026
@straight-shoota straight-shoota changed the title Fix Float32#abs to return self Fix Float32#abs to return Float32 Feb 11, 2026
@straight-shoota straight-shoota added this to the 1.20.0 milestone Feb 11, 2026
@straight-shoota straight-shoota merged commit 23b1aad into crystal-lang:master Feb 12, 2026
44 checks passed
@straight-shoota straight-shoota deleted the fix/float.abs branch February 12, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:regression Something that used to correctly work but no longer works topic:stdlib:numeric

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants