Trait fixed::traits::FixedBits

source ·
pub trait FixedBitswhere
    Self: Default + Hash + Ord + Contiguous + Pod + Debug + Display + LowerExp + UpperExp + Binary + Octal + LowerHex + UpperHex + FromStr<Err = ParseIntError> + Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign + Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign + Rem<Output = Self> + RemAssign + Not<Output = Self> + BitAnd<Output = Self> + BitAndAssign + BitOr<Output = Self> + BitOrAssign + BitXor<Output = Self> + BitXorAssign + Shl<u32, Output = Self> + ShlAssign<u32> + Shr<u32, Output = Self> + ShrAssign<u32> + Sum + Product + FixedEquiv + FixedBitsCast<i8> + FixedBitsCast<i16> + FixedBitsCast<i32> + FixedBitsCast<i64> + FixedBitsCast<i128> + FixedBitsCast<isize> + FixedBitsCast<u8> + FixedBitsCast<u16> + FixedBitsCast<u32> + FixedBitsCast<u64> + FixedBitsCast<u128> + FixedBitsCast<usize> + FixedBitsOptionalArbitrary + FixedBitsOptionalBorsh + FixedBitsOptionalNum + FixedBitsOptionalSerde + Sealed,
{ const MIN: Self; const MAX: Self; const IS_SIGNED: bool; const BITS: u32; }
Expand description

This trait is implemented for Fixed::Bits for all fixed-point numbers.

This provides some facilities to manipulate bits in generic functions.

This trait is sealed and cannot be implemented for more types; it is implemented for i8, i16, i32, i64, i128, u8, u16, u32, u64, and u128.

Examples

use az::OverflowingAs;
use fixed::{traits::Fixed, types::*};
fn limited_positive_bits<F: Fixed>(fixed: F) -> Option<u32> {
    let bits = fixed.to_bits();
    match bits.overflowing_as::<u32>() {
        (wrapped, false) => Some(wrapped),
        (_, true) => None,
    }
}
assert_eq!(limited_positive_bits(I16F16::from_bits(100)), Some(100));
assert_eq!(limited_positive_bits(I16F16::from_bits(-100)), None);

Required Associated Constants§

The smallest value that can be represented by this integer type.

The largest value that can be represented by this integer type.

true if this integer type is signed.

The size of this integer type in bits.

Implementations on Foreign Types§

Implementors§