Skip to main content

Module log

Module log 

Source
Expand description

Integer logarithms, mirroring the ilog2 / ilog10 / ilog inherent methods (stable in std since Rust 1.67) and their checked variants.

Split per base: ilog2 only needs leading_zeros — cheap and constant-time-implementable — while ilog10 and ilog require data-dependent division loops. Bundling them would force the expensive capability onto types that can only offer the cheap one. The panicking and checked variants stay paired within each trait: they share one capability, and the panicking form derives from the checked one.

CT tiers: Ilog2::checked_ilog2 is Tier B (a leading_zeros instruction plus an Option); the panicking ilog2 and all of Ilog10/Ilog are Tier C (data-dependent panic / division loops).

Traits§

Ilog
Integer logarithm with respect to an arbitrary base, rounded down.
Ilog2
Base 2 integer logarithm, rounded down.
Ilog10
Base 10 integer logarithm, rounded down.