Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Math.pw2ceil for all integer types #13127

Merged
merged 2 commits into from
Mar 2, 2023

Conversation

HertzDevil
Copy link
Contributor

Fixes #10514. This includes BigInt too.

The method is reworded in such a way that zero and negative inputs are expected to return 1. In particular, Math.pw2ceil(Int32::MIN) used to raise OverflowError, but now also returns 1.

Int#next_power_of_two is defined to make dynamic dispatch easier, compared to overloading Math.pw2ceil for each integer type individually; we could consider making it public later.

@HertzDevil HertzDevil added kind:bug kind:feature topic:stdlib:numeric kind:regression Something that used to correctly work but no longer works labels Feb 28, 2023
@straight-shoota straight-shoota added this to the 1.8.0 milestone Feb 28, 2023
@straight-shoota straight-shoota merged commit 6e9c356 into crystal-lang:master Mar 2, 2023
@HertzDevil HertzDevil deleted the bug/pw2ceil branch March 2, 2023 12:18
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug kind:feature 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.

Problems with Math.pw2ceil
3 participants