#[inline]
pub const fn u8(val: u8) -> u32 {
let val = val as u32;
const C1: u32 = 0b11_00000000 - 10; const C2: u32 = 0b10_00000000 - 100; ((val + C1) & (val + C2)) >> 8
}
#[inline]
const fn less_than_5(val: u32) -> u32 {
const C1: u32 = 0b011_00000000000000000 - 10; const C2: u32 = 0b100_00000000000000000 - 100; const C3: u32 = 0b111_00000000000000000 - 1000; const C4: u32 = 0b100_00000000000000000 - 10000; (((val + C1) & (val + C2)) ^ ((val + C3) & (val + C4))) >> 17
}
#[inline]
pub const fn u16(val: u16) -> u32 {
less_than_5(val as u32)
}
#[inline]
pub const fn u32(mut val: u32) -> u32 {
let mut log = 0;
if val >= 100_000 {
val /= 100_000;
log += 5;
}
log + less_than_5(val)
}
#[inline]
pub const fn u64(mut val: u64) -> u32 {
let mut log = 0;
if val >= 10_000_000_000 {
val /= 10_000_000_000;
log += 10;
}
if val >= 100_000 {
val /= 100_000;
log += 5;
}
log + less_than_5(val as u32)
}
#[inline]
pub const fn u128(mut val: u128) -> u32 {
let mut log = 0;
if val >= 100_000_000_000_000_000_000_000_000_000_000 {
val /= 100_000_000_000_000_000_000_000_000_000_000;
log += 32;
return log + u32(val as u32);
}
if val >= 10_000_000_000_000_000 {
val /= 10_000_000_000_000_000;
log += 16;
}
log + u64(val as u64)
}
#[cfg(target_pointer_width = "16")]
#[inline]
pub const fn usize(val: usize) -> u32 {
u16(val as _)
}
#[cfg(target_pointer_width = "32")]
#[inline]
pub const fn usize(val: usize) -> u32 {
u32(val as _)
}
#[cfg(target_pointer_width = "64")]
#[inline]
pub const fn usize(val: usize) -> u32 {
u64(val as _)
}
#[inline]
pub const fn i8(val: i8) -> u32 {
u8(val as u8)
}
#[inline]
pub const fn i16(val: i16) -> u32 {
u16(val as u16)
}
#[inline]
pub const fn i32(val: i32) -> u32 {
u32(val as u32)
}
#[inline]
pub const fn i64(val: i64) -> u32 {
u64(val as u64)
}
#[inline]
pub const fn i128(val: i128) -> u32 {
u128(val as u128)
}
#[cold]
#[track_caller]
pub const fn panic_for_nonpositive_argument() -> ! {
panic!("argument of integer logarithm must be positive")
}