Skip to content

Commit 9bd198f

Browse files
authored
Constant log2 (#49)
1 parent e18cd56 commit 9bd198f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ pub use num_traits::{One, Zero};
7575
/// assert_eq!(log2(1 << 15), 15);
7676
/// assert_eq!(log2(2usize.pow(18)), 18);
7777
/// ```
78-
pub fn log2(x: usize) -> u32 {
78+
#[inline(always)]
79+
pub const fn log2(x: usize) -> u32 {
7980
if x == 0 {
8081
0
8182
} else if x.is_power_of_two() {

0 commit comments

Comments
 (0)