modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.38k stars 2.6k forks source link

[Feature Request] Rename `bit_ceil` and `bit_floor` to `closest_pow_2_ge` and `closest_pow_2_le` #3271

Open martinvuyk opened 4 months ago

martinvuyk commented 4 months ago

Review Mojo's priorities

What is your request?

Rename bit_ceil and bit_floor to closest_pow_2_ge and closest_pow_2_le.

Similarly as issue #3158, I think some renaming would be fitting here. I know these names come from C++, but some verbosity and clearer use case is better when looking for something and not intuitively understanding what the function name means.

In my particular case, I literally reimplemented bit_ceil with bitshifting (100% copied from stack overflow) because I was looking for the closest power of two greater than or equal to a dynamic value. And I was literally writing the code to include in a PR when I read the code for bit_ceil

What is your motivation for this change?

Verbose names in exchange for clarity. Also, extending the naming to include closest_pow_2_gt and closest_pow_2_lt becomes clear and simple.

Any other details?

No response

JoeLoser commented 3 months ago

Thanks for filing the issue! We talked about this internally earlier this week and decided on the names: next_power_of_two and prev_power_of_two. This is taking inspiration from the Rust https://doc.rust-lang.org/std/primitive.usize.html#method.next_power_of_two.