Module malachite_base::num::arithmetic::log_base_2
source · Expand description
Traits for taking the base-2 logarithm of a number.
The traits are FloorLogBase2
,
CeilingLogBase2
, and CheckedLogBase2
.
§floor_log_base_2
use malachite_base::num::arithmetic::traits::FloorLogBase2;
assert_eq!(1u8.floor_log_base_2(), 0);
assert_eq!(100u64.floor_log_base_2(), 6);
assert_eq!(1.0f32.floor_log_base_2(), 0);
assert_eq!(100.0f32.floor_log_base_2(), 6);
assert_eq!(0.1f32.floor_log_base_2(), -4);
§ceiling_log_base_2
use malachite_base::num::arithmetic::traits::CeilingLogBase2;
assert_eq!(1u8.ceiling_log_base_2(), 0);
assert_eq!(100u64.ceiling_log_base_2(), 7);
assert_eq!(1.0f32.ceiling_log_base_2(), 0);
assert_eq!(100.0f32.ceiling_log_base_2(), 7);
assert_eq!(0.1f32.ceiling_log_base_2(), -3);
§checked_log_base_2
use malachite_base::num::arithmetic::traits::CheckedLogBase2;
assert_eq!(1u8.checked_log_base_2(), Some(0));
assert_eq!(100u64.checked_log_base_2(), None);
assert_eq!(128u64.checked_log_base_2(), Some(7));
assert_eq!(1.0f32.checked_log_base_2(), Some(0));
assert_eq!(100.0f32.checked_log_base_2(), None);
assert_eq!(128.0f32.checked_log_base_2(), Some(7));
assert_eq!(0.1f32.checked_log_base_2(), None);
assert_eq!(0.0625f32.checked_log_base_2(), Some(-4));