Skip to content

Commit

Permalink
Constant log2 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy authored Jul 9, 2024
1 parent e18cd56 commit 9bd198f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ pub use num_traits::{One, Zero};
/// assert_eq!(log2(1 << 15), 15);
/// assert_eq!(log2(2usize.pow(18)), 18);
/// ```
pub fn log2(x: usize) -> u32 {
#[inline(always)]
pub const fn log2(x: usize) -> u32 {
if x == 0 {
0
} else if x.is_power_of_two() {
Expand Down

0 comments on commit 9bd198f

Please sign in to comment.