Trait PowerOfTwo

Source
pub trait PowerOfTwo {
    // Required methods
    fn is_power_of_two(&self) -> bool;
    fn next_power_of_two(self) -> Self;
}
Expand description

Functions related to the power of two.

§Examples

use dashu_base::PowerOfTwo;

let n = 5u32;
assert!(!n.is_power_of_two());
assert_eq!(n.next_power_of_two(), 8);

Required Methods§

Source

fn is_power_of_two(&self) -> bool

Test if self is a power of two (2^k)

Source

fn next_power_of_two(self) -> Self

Get the smallest power of two greater than or equal to self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl PowerOfTwo for u8

Source§

impl PowerOfTwo for u16

Source§

impl PowerOfTwo for u32

Source§

impl PowerOfTwo for u64

Source§

impl PowerOfTwo for u128

Source§

impl PowerOfTwo for usize

Implementors§