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

Use Int#bit_length instead of Math.log2 followed by #to_i #13440

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented May 5, 2023

If x is a positive integer, then Math.log2(x).to_i == x.bit_length - 1. This identity allows us to remove some unnecessary floating-point computations. Here it is guaranteed that initial_indices_size >= 16 and n >= 2 respectively.

@straight-shoota straight-shoota added this to the 1.9.0 milestone May 5, 2023
@straight-shoota straight-shoota merged commit 98c091e into crystal-lang:master May 8, 2023
@HertzDevil HertzDevil deleted the refactor/math-log2-to_i branch May 8, 2023 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants