Module malachite_base::num::arithmetic::log_base_power_of_2
source · Expand description
Traits for taking the base-$2^k$ logarithm of a number.
The traits are FloorLogBasePowerOf2
,
CeilingLogBasePowerOf2
, and
CheckedLogBasePowerOf2
.
§floor_log_base_power_of_2
use malachite_base::num::arithmetic::traits::FloorLogBasePowerOf2;
assert_eq!(1u8.floor_log_base_power_of_2(4), 0);
assert_eq!(100u64.floor_log_base_power_of_2(2), 3);
assert_eq!(0.1f32.floor_log_base_power_of_2(2), -2);
§ceiling_log_base_power_of_2
use malachite_base::num::arithmetic::traits::CeilingLogBasePowerOf2;
assert_eq!(1u8.ceiling_log_base_power_of_2(4), 0);
assert_eq!(100u64.ceiling_log_base_power_of_2(2), 4);
assert_eq!(0.1f32.ceiling_log_base_power_of_2(2), -1);
§checked_log_base_power_of_2
use malachite_base::num::arithmetic::traits::CheckedLogBasePowerOf2;
assert_eq!(1u8.checked_log_base_power_of_2(4), Some(0));
assert_eq!(100u64.checked_log_base_power_of_2(4), None);
assert_eq!(256u64.checked_log_base_power_of_2(4), Some(2));
assert_eq!(0.1f32.checked_log_base_power_of_2(2), None);
assert_eq!(0.0625f32.checked_log_base_power_of_2(2), Some(-2));