Trait PowersOf2

Source
pub trait PowersOf2 {
    // Required methods
    fn powerOf2(self) -> bool;
    fn nextPowerOf2(self) -> usize;
    fn log2(self) -> u8;
}
Expand description

Basic power-of-2 integer math.

Required Methods§

Source

fn powerOf2(self) -> bool

Source

fn nextPowerOf2(self) -> usize

Source

fn log2(self) -> u8

Implementations on Foreign Types§

Source§

impl PowersOf2 for usize

Source§

fn powerOf2(self) -> bool

This code is based on http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2

Source§

fn nextPowerOf2(self) -> usize

Calculate the next power of two.

Based on http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2

Source§

fn log2(self) -> u8

Calculate the base-2 logarithm of this value.

This will normally round down, except for the case of 0.log2(), which will return 0.

Based on the obvious code at http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious

Implementors§