Module malachite_base::num::arithmetic::log_base
source · Expand description
Traits for taking the base-$b$ logarithm of a number.
The traits are FloorLogBase
,
CeilingLogBase
, and CheckedLogBase
.
§floor_log_base
use malachite_base::num::arithmetic::traits::FloorLogBase;
assert_eq!(1u8.floor_log_base(5), 0);
assert_eq!(125u8.floor_log_base(5), 3);
assert_eq!(99u64.floor_log_base(10), 1);
assert_eq!(100u64.floor_log_base(10), 2);
assert_eq!(101u64.floor_log_base(10), 2);
§ceiling_log_base
use malachite_base::num::arithmetic::traits::CeilingLogBase;
assert_eq!(1u8.ceiling_log_base(5), 0);
assert_eq!(125u8.ceiling_log_base(5), 3);
assert_eq!(99u64.ceiling_log_base(10), 2);
assert_eq!(100u64.ceiling_log_base(10), 2);
assert_eq!(101u64.ceiling_log_base(10), 3);
§checked_log_base
use malachite_base::num::arithmetic::traits::CheckedLogBase;
assert_eq!(1u8.checked_log_base(5), Some(0));
assert_eq!(125u8.checked_log_base(5), Some(3));
assert_eq!(99u64.checked_log_base(10), None);
assert_eq!(100u64.checked_log_base(10), Some(2));
assert_eq!(101u64.checked_log_base(10), None);