ilog
Base 10 and 2 logarithm functions for integer types.
The IntLog
trait defines the following methods:
The log2
and log10
methods are optimized for the integer width and are
[inline]
as long as the code remains small enough. They typically use constant tables
that are only stored once, even if the methods using them are inlined multiple times.
The checked versions of the methods, checked_log2
and checked_log10
,
return None
if the logarithm is undefined for the parameter value, whereas the unchecked
methods mentioned above simply panic. A default implementation is provided in the trait, and in
most cases they needn't be overidden.
Examples
use IntLog;
let hundred: u32 = 100;
assert_eq!;
assert_eq!;
let value: u64 = 256;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Usage
Add this dependency to your Cargo.toml
file:
[]
= "0"
Compatibility
The ilog
crate is tested for rustc 1.65 and greater.
License
Licensed under MIT license.