Trait fixed::traits::Fixed[][src]

pub trait Fixed where
    Self: Copy + Default + Hash + Ord,
    Self: Debug + Display + Binary + Octal + LowerHex + UpperHex,
    Self: FromStr<Err = ParseFixedError>,
    Self: FromFixed + ToFixed,
    Self: Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign,
    Self: Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign,
    Self: Rem<Output = Self> + RemAssign,
    Self: Mul<Self::Bits, Output = Self> + MulAssign<Self::Bits>,
    Self: Div<Self::Bits, Output = Self> + DivAssign<Self::Bits>,
    Self: Rem<Self::Bits, Output = Self> + RemAssign<Self::Bits>,
    Self: Not<Output = Self> + BitAnd<Output = Self> + BitAndAssign,
    Self: BitOr<Output = Self> + BitOrAssign + BitXor<Output = Self> + BitXorAssign,
    Self: Shl<u32, Output = Self> + ShlAssign<u32> + Shr<u32, Output = Self> + ShrAssign<u32>,
    Self: PartialOrd<i8> + PartialOrd<i16> + PartialOrd<i32>,
    Self: PartialOrd<i64> + PartialOrd<i128> + PartialOrd<isize>,
    Self: PartialOrd<u8> + PartialOrd<u16> + PartialOrd<u32>,
    Self: PartialOrd<u64> + PartialOrd<u128> + PartialOrd<usize>,
    Self: PartialOrd<f32> + PartialOrd<f64>,
    Self: FixedOptionalFeatures,
    Self: Sealed, 
{ type Bits; type Bytes; type Frac: Unsigned; const MIN: Self; const MAX: Self; const INT_NBITS: u32; const FRAC_NBITS: u32; fn from_bits(bits: Self::Bits) -> Self;
fn to_bits(self) -> Self::Bits;
fn from_be_bytes(bytes: Self::Bytes) -> Self;
fn from_le_bytes(bytes: Self::Bytes) -> Self;
fn from_ne_bytes(bytes: Self::Bytes) -> Self;
fn to_be_bytes(self) -> Self::Bytes;
fn to_le_bytes(self) -> Self::Bytes;
fn to_ne_bytes(self) -> Self::Bytes;
fn from_num<Src: ToFixed>(src: Src) -> Self;
fn to_num<Dst: FromFixed>(self) -> Dst;
fn checked_from_num<Src: ToFixed>(src: Src) -> Option<Self>;
fn checked_to_num<Dst: FromFixed>(self) -> Option<Dst>;
fn saturating_from_num<Src: ToFixed>(src: Src) -> Self;
fn saturating_to_num<Dst: FromFixed>(self) -> Dst;
fn wrapping_from_num<Src: ToFixed>(src: Src) -> Self;
fn wrapping_to_num<Dst: FromFixed>(self) -> Dst;
fn unwrapped_from_num<Src: ToFixed>(src: Src) -> Self;
fn unwrapped_to_num<Dst: FromFixed>(self) -> Dst;
fn overflowing_from_num<Src: ToFixed>(src: Src) -> (Self, bool);
fn overflowing_to_num<Dst: FromFixed>(self) -> (Dst, bool);
fn from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
fn from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
fn from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
fn saturating_from_str(src: &str) -> Result<Self, ParseFixedError>;
fn saturating_from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
fn saturating_from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
fn saturating_from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
fn wrapping_from_str(src: &str) -> Result<Self, ParseFixedError>;
fn wrapping_from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
fn wrapping_from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
fn wrapping_from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
fn overflowing_from_str(src: &str) -> Result<(Self, bool), ParseFixedError>;
fn overflowing_from_str_binary(
        src: &str
    ) -> Result<(Self, bool), ParseFixedError>;
fn overflowing_from_str_octal(
        src: &str
    ) -> Result<(Self, bool), ParseFixedError>;
fn overflowing_from_str_hex(
        src: &str
    ) -> Result<(Self, bool), ParseFixedError>;
fn int(self) -> Self;
fn frac(self) -> Self;
fn round_to_zero(self) -> Self;
fn ceil(self) -> Self;
fn floor(self) -> Self;
fn round(self) -> Self;
fn round_ties_to_even(self) -> Self;
fn checked_ceil(self) -> Option<Self>;
fn checked_floor(self) -> Option<Self>;
fn checked_round(self) -> Option<Self>;
fn checked_round_ties_to_even(self) -> Option<Self>;
fn saturating_ceil(self) -> Self;
fn saturating_floor(self) -> Self;
fn saturating_round(self) -> Self;
fn saturating_round_ties_to_even(self) -> Self;
fn wrapping_ceil(self) -> Self;
fn wrapping_floor(self) -> Self;
fn wrapping_round(self) -> Self;
fn wrapping_round_ties_to_even(self) -> Self;
fn unwrapped_ceil(self) -> Self;
fn unwrapped_floor(self) -> Self;
fn unwrapped_round(self) -> Self;
fn unwrapped_round_ties_to_even(self) -> Self;
fn overflowing_ceil(self) -> (Self, bool);
fn overflowing_floor(self) -> (Self, bool);
fn overflowing_round(self) -> (Self, bool);
fn overflowing_round_ties_to_even(self) -> (Self, bool);
fn count_ones(self) -> u32;
fn count_zeros(self) -> u32;
fn leading_ones(self) -> u32;
fn leading_zeros(self) -> u32;
fn trailing_ones(self) -> u32;
fn trailing_zeros(self) -> u32;
fn int_log2(self) -> i32;
fn int_log10(self) -> i32;
fn checked_int_log2(self) -> Option<i32>;
fn checked_int_log10(self) -> Option<i32>;
fn rotate_left(self, n: u32) -> Self;
fn rotate_right(self, n: u32) -> Self;
fn recip(self) -> Self;
fn mul_add(self, mul: Self, add: Self) -> Self;
fn div_euclid(self, rhs: Self) -> Self;
fn rem_euclid(self, rhs: Self) -> Self;
fn div_euclid_int(self, rhs: Self::Bits) -> Self;
fn rem_euclid_int(self, rhs: Self::Bits) -> Self;
fn checked_neg(self) -> Option<Self>;
fn checked_add(self, rhs: Self) -> Option<Self>;
fn checked_sub(self, rhs: Self) -> Option<Self>;
fn checked_mul(self, rhs: Self) -> Option<Self>;
fn checked_div(self, rhs: Self) -> Option<Self>;
fn checked_rem(self, rhs: Self) -> Option<Self>;
fn checked_recip(self) -> Option<Self>;
fn checked_mul_add(self, mul: Self, add: Self) -> Option<Self>;
fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
fn checked_mul_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_div_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_rem_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_div_euclid_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_rem_euclid_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_shl(self, rhs: u32) -> Option<Self>;
fn checked_shr(self, rhs: u32) -> Option<Self>;
fn saturating_neg(self) -> Self;
fn saturating_add(self, rhs: Self) -> Self;
fn saturating_sub(self, rhs: Self) -> Self;
fn saturating_mul(self, rhs: Self) -> Self;
fn saturating_div(self, rhs: Self) -> Self;
fn saturating_recip(self) -> Self;
fn saturating_mul_add(self, mul: Self, add: Self) -> Self;
fn saturating_div_euclid(self, rhs: Self) -> Self;
fn saturating_mul_int(self, rhs: Self::Bits) -> Self;
fn wrapping_neg(self) -> Self;
fn wrapping_add(self, rhs: Self) -> Self;
fn wrapping_sub(self, rhs: Self) -> Self;
fn wrapping_mul(self, rhs: Self) -> Self;
fn wrapping_div(self, rhs: Self) -> Self;
fn wrapping_recip(self) -> Self;
fn wrapping_mul_add(self, mul: Self, add: Self) -> Self;
fn wrapping_div_euclid(self, rhs: Self) -> Self;
fn wrapping_mul_int(self, rhs: Self::Bits) -> Self;
fn wrapping_div_int(self, rhs: Self::Bits) -> Self;
fn wrapping_div_euclid_int(self, rhs: Self::Bits) -> Self;
fn wrapping_rem_euclid_int(self, rhs: Self::Bits) -> Self;
fn wrapping_shl(self, rhs: u32) -> Self;
fn wrapping_shr(self, rhs: u32) -> Self;
fn unwrapped_neg(self) -> Self;
fn unwrapped_add(self, rhs: Self) -> Self;
fn unwrapped_sub(self, rhs: Self) -> Self;
fn unwrapped_mul(self, rhs: Self) -> Self;
fn unwrapped_div(self, rhs: Self) -> Self;
fn unwrapped_recip(self) -> Self;
fn unwrapped_mul_add(self, mul: Self, add: Self) -> Self;
fn unwrapped_div_euclid(self, rhs: Self) -> Self;
fn unwrapped_mul_int(self, rhs: Self::Bits) -> Self;
fn unwrapped_div_int(self, rhs: Self::Bits) -> Self;
fn unwrapped_div_euclid_int(self, rhs: Self::Bits) -> Self;
fn unwrapped_rem_euclid_int(self, rhs: Self::Bits) -> Self;
fn unwrapped_shl(self, rhs: u32) -> Self;
fn unwrapped_shr(self, rhs: u32) -> Self;
fn overflowing_neg(self) -> (Self, bool);
fn overflowing_add(self, rhs: Self) -> (Self, bool);
fn overflowing_sub(self, rhs: Self) -> (Self, bool);
fn overflowing_mul(self, rhs: Self) -> (Self, bool);
fn overflowing_div(self, rhs: Self) -> (Self, bool);
fn overflowing_recip(self) -> (Self, bool);
fn overflowing_mul_add(self, mul: Self, add: Self) -> (Self, bool);
fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool);
fn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_div_euclid_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_rem_euclid_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_shl(self, rhs: u32) -> (Self, bool);
fn overflowing_shr(self, rhs: u32) -> (Self, bool); }

This trait provides methods common to all fixed-point numbers.

It can be helpful when writing generic code that makes use of fixed-point numbers. For methods only available on signed fixed-point numbers, use the FixedSigned trait instead, and for methods only available on unsigned fixed-point numbers, use FixedUnsigned.

This trait is sealed and cannot be implemented for more types; it is implemented for FixedI8, FixedI16, FixedI32, FixedI64, FixedI128, FixedU8, FixedU16, FixedU32, FixedU64, and FixedU128.

Examples

use fixed::{
    traits::Fixed,
    types::{I8F8, I16F16},
};

fn checked_add_twice<F: Fixed>(lhs: F, rhs: F) -> Option<F> {
    lhs.checked_add(rhs)?.checked_add(rhs)
}

let val1 = checked_add_twice(I8F8::from_num(5), Fixed::from_num(1.75));
assert_eq!(val1, Some(Fixed::from_num(8.5)));
// can use with different fixed-point type
let val2 = checked_add_twice(I16F16::from_num(5), Fixed::from_num(1.75));
assert_eq!(val2, Some(Fixed::from_num(8.5)));

The following example fails to compile, since the compiler cannot infer that 500 in the checked_mul_int call is of type F::Bits.

use fixed::traits::Fixed;

fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F> {
    rhs.checked_mul_int(500)?.checked_add(lhs)
}

One way to fix this is to add a trait bound indicating that any u16 (which can represent 500) can be converted into F::Bits.

use fixed::{traits::Fixed, types::U12F4};

fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
where
    u16: Into<F::Bits>,
{
    rhs.checked_mul_int(500.into())?.checked_add(lhs)
}

let val = checked_add_times_500(U12F4::from_num(0.25), Fixed::from_num(1.5));
assert_eq!(val, Some(Fixed::from_num(750.25)));

While this works in most cases, u16 cannot be converted to i16, even if the value 500 does fit in i16, so that the following example would fail to compile.

use fixed::{traits::Fixed, types::I12F4};

fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
where
    u16: Into<F::Bits>,
{
    rhs.checked_mul_int(500.into())?.checked_add(lhs)
}

// I12F4::Bits is i16, and u16 does not implement Into<i16>
let val = checked_add_times_500(I12F4::from_num(0.25), Fixed::from_num(1.5));

We can use TryFrom to fix this, as we know that F::Bits::try_from(500_u16) will work for both u16 and i16. (The function will always return None when F::Bits is u8 or i8.)

use fixed::{traits::Fixed, types::I12F4};
use core::convert::TryInto;

fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
where
    u16: TryInto<F::Bits>,
{
    rhs.checked_mul_int(500.try_into().ok()?)?.checked_add(lhs)
}

let val = checked_add_times_500(I12F4::from_num(0.25), Fixed::from_num(1.5));
assert_eq!(val, Some(Fixed::from_num(750.25)));

Associated Types

type Bits[src]

The primitive integer underlying type.

type Bytes[src]

A byte array with the same size as the type.

type Frac: Unsigned[src]

The number of fractional bits.

<F as Fixed>::Frac::U32 is equivalent to <F as Fixed>::FRAC_NBITS.

Loading content...

Associated Constants

const MIN: Self[src]

The smallest value that can be represented.

const MAX: Self[src]

The largest value that can be represented.

const INT_NBITS: u32[src]

The number of integer bits.

const FRAC_NBITS: u32[src]

The number of fractional bits.

Loading content...

Required methods

fn from_bits(bits: Self::Bits) -> Self[src]

Creates a fixed-point number that has a bitwise representation identical to the given integer.

fn to_bits(self) -> Self::Bits[src]

Creates an integer that has a bitwise representation identical to the given fixed-point number.

fn from_be_bytes(bytes: Self::Bytes) -> Self[src]

Creates a fixed-point number from its representation as a byte array in big endian.

fn from_le_bytes(bytes: Self::Bytes) -> Self[src]

Creates a fixed-point number from its representation as a byte array in little endian.

fn from_ne_bytes(bytes: Self::Bytes) -> Self[src]

Creates a fixed-point number from its representation as a byte array in native endian.

fn to_be_bytes(self) -> Self::Bytes[src]

Returns the memory representation of this fixed-point number as a byte array in big-endian byte order.

fn to_le_bytes(self) -> Self::Bytes[src]

Returns the memory representation of this fixed-point number as a byte array in little-endian byte order.

fn to_ne_bytes(self) -> Self::Bytes[src]

Returns the memory representation of this fixed-point number as a byte array in native byte order.

fn from_num<Src: ToFixed>(src: Src) -> Self[src]

Creates a fixed-point number from another number.

Returns the same value as src.to_fixed().

fn to_num<Dst: FromFixed>(self) -> Dst[src]

Converts a fixed-point number to another number.

Returns the same value as Dst::from_fixed(self).

fn checked_from_num<Src: ToFixed>(src: Src) -> Option<Self>[src]

Creates a fixed-point number from another number if it fits, otherwise returns None.

Returns the same value as src.checked_to_fixed().

fn checked_to_num<Dst: FromFixed>(self) -> Option<Dst>[src]

Converts a fixed-point number to another number if it fits, otherwise returns None.

Returns the same value as Dst::checked_from_fixed(self).

fn saturating_from_num<Src: ToFixed>(src: Src) -> Self[src]

Creates a fixed-point number from another number, saturating the value if it does not fit.

Returns the same value as src.saturating_to_fixed().

fn saturating_to_num<Dst: FromFixed>(self) -> Dst[src]

Converts a fixed-point number to another number, saturating the value if it does not fit.

Returns the same value as Dst::saturating_from_fixed(self).

fn wrapping_from_num<Src: ToFixed>(src: Src) -> Self[src]

Creates a fixed-point number from another number, wrapping the value on overflow.

Returns the same value as src.wrapping_to_fixed().

fn wrapping_to_num<Dst: FromFixed>(self) -> Dst[src]

Converts a fixed-point number to another number, wrapping the value on overflow.

Returns the same value as Src::wrapping_from_fixed(self).

fn unwrapped_from_num<Src: ToFixed>(src: Src) -> Self[src]

Creates a fixed-point number from another number, panicking on overflow.

Panics

Panics if the value does not fit.

fn unwrapped_to_num<Dst: FromFixed>(self) -> Dst[src]

Converts a fixed-point number to another number, panicking on overflow.

Panics

Panics if the value does not fit.

fn overflowing_from_num<Src: ToFixed>(src: Src) -> (Self, bool)[src]

Creates a fixed-point number from another number.

Returns the same value as src.overflowing_to_fixed().

fn overflowing_to_num<Dst: FromFixed>(self) -> (Dst, bool)[src]

Converts a fixed-point number to another number.

Returns the same value as Dst::overflowing_from_fixed(self).

fn from_str_binary(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing binary digits to return a fixed-point number.

Rounding is to the nearest, with ties rounded to even.

fn from_str_octal(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing octal digits to return a fixed-point number.

Rounding is to the nearest, with ties rounded to even.

fn from_str_hex(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing hexadecimal digits to return a fixed-point number.

Rounding is to the nearest, with ties rounded to even.

fn saturating_from_str(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing decimal digits to return a fixed-point number, saturating on overflow.

Rounding is to the nearest, with ties rounded to even.

fn saturating_from_str_binary(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing binary digits to return a fixed-point number, saturating on overflow.

Rounding is to the nearest, with ties rounded to even.

fn saturating_from_str_octal(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing octal digits to return a fixed-point number, saturating on overflow.

Rounding is to the nearest, with ties rounded to even.

fn saturating_from_str_hex(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing hexadecimal digits to return a fixed-point number, saturating on overflow.

Rounding is to the nearest, with ties rounded to even.

fn wrapping_from_str(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing decimal digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

fn wrapping_from_str_binary(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing binary digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

fn wrapping_from_str_octal(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing octal digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

fn wrapping_from_str_hex(src: &str) -> Result<Self, ParseFixedError>[src]

Parses a string slice containing hexadecimal digits to return a fixed-point number, wrapping on overflow.

Rounding is to the nearest, with ties rounded to even.

fn overflowing_from_str(src: &str) -> Result<(Self, bool), ParseFixedError>[src]

Parses a string slice containing decimal digits to return a fixed-point number.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Rounding is to the nearest, with ties rounded to even.

fn overflowing_from_str_binary(
    src: &str
) -> Result<(Self, bool), ParseFixedError>
[src]

Parses a string slice containing binary digits to return a fixed-point number.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Rounding is to the nearest, with ties rounded to even.

fn overflowing_from_str_octal(
    src: &str
) -> Result<(Self, bool), ParseFixedError>
[src]

Parses a string slice containing octal digits to return a fixed-point number.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Rounding is to the nearest, with ties rounded to even.

fn overflowing_from_str_hex(src: &str) -> Result<(Self, bool), ParseFixedError>[src]

Parses a string slice containing hexadecimal digits to return a fixed-point number.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Rounding is to the nearest, with ties rounded to even.

fn int(self) -> Self[src]

Returns the integer part.

fn frac(self) -> Self[src]

Returns the fractional part.

fn round_to_zero(self) -> Self[src]

Rounds to the next integer towards 0.

fn ceil(self) -> Self[src]

Rounds to the next integer towards +∞.

fn floor(self) -> Self[src]

Rounds to the next integer towards −∞.

fn round(self) -> Self[src]

Rounds to the nearest integer, with ties rounded away from zero.

fn round_ties_to_even(self) -> Self[src]

Rounds to the nearest integer, with ties rounded to even.

fn checked_ceil(self) -> Option<Self>[src]

Checked ceil. Rounds to the next integer towards +∞, returning None on overflow.

fn checked_floor(self) -> Option<Self>[src]

Checked floor. Rounds to the next integer towards −∞, returning None on overflow.

fn checked_round(self) -> Option<Self>[src]

Checked round. Rounds to the nearest integer, with ties rounded away from zero, returning None on overflow.

fn checked_round_ties_to_even(self) -> Option<Self>[src]

Checked round. Rounds to the nearest integer, with ties rounded to even, returning None on overflow.

fn saturating_ceil(self) -> Self[src]

Saturating ceil. Rounds to the next integer towards +∞, saturating on overflow.

fn saturating_floor(self) -> Self[src]

Saturating floor. Rounds to the next integer towards −∞, saturating on overflow.

fn saturating_round(self) -> Self[src]

Saturating round. Rounds to the nearest integer, with ties rounded away from zero, and saturating on overflow.

fn saturating_round_ties_to_even(self) -> Self[src]

Saturating round. Rounds to the nearest integer, with ties rounded to_even, and saturating on overflow.

fn wrapping_ceil(self) -> Self[src]

Wrapping ceil. Rounds to the next integer towards +∞, wrapping on overflow.

fn wrapping_floor(self) -> Self[src]

Wrapping floor. Rounds to the next integer towards −∞, wrapping on overflow.

fn wrapping_round(self) -> Self[src]

Wrapping round. Rounds to the next integer to the nearest, with ties rounded away from zero, and wrapping on overflow.

fn wrapping_round_ties_to_even(self) -> Self[src]

Wrapping round. Rounds to the next integer to the nearest, with ties rounded to even, and wrapping on overflow.

fn unwrapped_ceil(self) -> Self[src]

Unwrapped ceil. Rounds to the next integer towards +∞, panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_floor(self) -> Self[src]

Unwrapped floor. Rounds to the next integer towards −∞, panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_round(self) -> Self[src]

Unwrapped round. Rounds to the next integer to the nearest, with ties rounded away from zero, and panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_round_ties_to_even(self) -> Self[src]

Unwrapped round. Rounds to the next integer to the nearest, with ties rounded to even, and panicking on overflow.

Panics

Panics if the result does not fit.

fn overflowing_ceil(self) -> (Self, bool)[src]

Overflowing ceil. Rounds to the next integer towards +∞.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_floor(self) -> (Self, bool)[src]

Overflowing floor. Rounds to the next integer towards −∞.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_round(self) -> (Self, bool)[src]

Overflowing round. Rounds to the next integer to the nearest, with ties rounded away from zero.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_round_ties_to_even(self) -> (Self, bool)[src]

Overflowing round. Rounds to the next integer to the nearest, with ties rounded to even.

Returns a tuple of the fixed-point number and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn count_ones(self) -> u32[src]

Returns the number of ones in the binary representation.

fn count_zeros(self) -> u32[src]

Returns the number of zeros in the binary representation.

fn leading_ones(self) -> u32[src]

Returns the number of leading ones in the binary representation.

fn leading_zeros(self) -> u32[src]

Returns the number of leading zeros in the binary representation.

fn trailing_ones(self) -> u32[src]

Returns the number of trailing ones in the binary representation.

fn trailing_zeros(self) -> u32[src]

Returns the number of trailing zeros in the binary representation.

fn int_log2(self) -> i32[src]

Integer base-2 logarithm, rounded down.

Panics

Panics if the fixed-point number is ≤ 0.

fn int_log10(self) -> i32[src]

Integer base-10 logarithm, rounded down.

Panics

Panics if the fixed-point number is ≤ 0.

fn checked_int_log2(self) -> Option<i32>[src]

Checked integer base-2 logarithm, rounded down. Returns the logarithm or None if the fixed-point number is ≤ 0.

fn checked_int_log10(self) -> Option<i32>[src]

Checked integer base-10 logarithm, rounded down. Returns the logarithm or None if the fixed-point number is ≤ 0.

fn rotate_left(self, n: u32) -> Self[src]

Shifts to the left by n bits, wrapping the truncated bits to the right end.

fn rotate_right(self, n: u32) -> Self[src]

Shifts to the right by n bits, wrapping the truncated bits to the left end.

fn recip(self) -> Self[src]

Returns the reciprocal.

Panics

Panics if self is zero.

fn mul_add(self, mul: Self, add: Self) -> Self[src]

Multiply and add. Returns self × mul + add.

Note that the inherent mul_add method is more flexible than this method and allows the mul parameter to have a fixed-point type like self but with a different number of fractional bits.

fn div_euclid(self, rhs: Self) -> Self[src]

Euclidean division by an integer.

Panics

Panics if the divisor is zero or if the division results in overflow.

fn rem_euclid(self, rhs: Self) -> Self[src]

Remainder for Euclidean division.

Panics

Panics if the divisor is zero.

fn div_euclid_int(self, rhs: Self::Bits) -> Self[src]

Euclidean division by an integer.

Panics

Panics if the divisor is zero or if the division results in overflow.

fn rem_euclid_int(self, rhs: Self::Bits) -> Self[src]

Remainder for Euclidean division by an integer.

Panics

Panics if the divisor is zero or if the division results in overflow.

fn checked_neg(self) -> Option<Self>[src]

Checked negation. Returns the negated value, or None on overflow.

fn checked_add(self, rhs: Self) -> Option<Self>[src]

Checked addition. Returns the sum, or None on overflow.

fn checked_sub(self, rhs: Self) -> Option<Self>[src]

Checked subtraction. Returns the difference, or None on overflow.

fn checked_mul(self, rhs: Self) -> Option<Self>[src]

Checked multiplication. Returns the product, or None on overflow.

fn checked_div(self, rhs: Self) -> Option<Self>[src]

Checked division. Returns the quotient, or None if the divisor is zero or on overflow.

fn checked_rem(self, rhs: Self) -> Option<Self>[src]

Checked remainder. Returns the remainder, or None if the divisor is zero.

fn checked_recip(self) -> Option<Self>[src]

Checked reciprocal. Returns the reciprocal, or None if self is zero or on overflow.

fn checked_mul_add(self, mul: Self, add: Self) -> Option<Self>[src]

Checked multiply and add. Returns self × mul + add, or None on overflow.

fn checked_div_euclid(self, rhs: Self) -> Option<Self>[src]

Checked remainder for Euclidean division. Returns the remainder, or None if the divisor is zero or the division results in overflow.

fn checked_rem_euclid(self, rhs: Self) -> Option<Self>[src]

Checked remainder for Euclidean division. Returns the remainder, or None if the divisor is zero.

fn checked_mul_int(self, rhs: Self::Bits) -> Option<Self>[src]

Checked multiplication by an integer. Returns the product, or None on overflow.

fn checked_div_int(self, rhs: Self::Bits) -> Option<Self>[src]

Checked division by an integer. Returns the quotient, or None if the divisor is zero or if the division results in overflow.

fn checked_rem_int(self, rhs: Self::Bits) -> Option<Self>[src]

Checked fixed-point remainder for division by an integer. Returns the remainder, or None if the divisor is zero or if the division results in overflow.

fn checked_div_euclid_int(self, rhs: Self::Bits) -> Option<Self>[src]

Checked Euclidean division by an integer. Returns the quotient, or None if the divisor is zero or if the division results in overflow.

fn checked_rem_euclid_int(self, rhs: Self::Bits) -> Option<Self>[src]

Checked remainder for Euclidean division by an integer. Returns the remainder, or None if the divisor is zero or if the remainder results in overflow.

fn checked_shl(self, rhs: u32) -> Option<Self>[src]

Checked shift left. Returns the shifted number, or None if rhs ≥ the number of bits.

fn checked_shr(self, rhs: u32) -> Option<Self>[src]

Checked shift right. Returns the shifted number, or None if rhs ≥ the number of bits.

fn saturating_neg(self) -> Self[src]

Saturated negation. Returns the negated value, saturating on overflow.

fn saturating_add(self, rhs: Self) -> Self[src]

Saturating addition. Returns the sum, saturating on overflow.

fn saturating_sub(self, rhs: Self) -> Self[src]

Saturating subtraction. Returns the difference, saturating on overflow.

fn saturating_mul(self, rhs: Self) -> Self[src]

Saturating multiplication. Returns the product, saturating on overflow.

fn saturating_div(self, rhs: Self) -> Self[src]

Saturating division. Returns the quotient, saturating on overflow.

Panics

Panics if the divisor is zero.

fn saturating_recip(self) -> Self[src]

Saturating reciprocal.

Panics

Panics if self is zero.

fn saturating_mul_add(self, mul: Self, add: Self) -> Self[src]

Saturating multiply and add. Returns self × mul + add, saturating on overflow.

fn saturating_div_euclid(self, rhs: Self) -> Self[src]

Saturating Euclidean division. Returns the quotient, saturating on overflow.

Panics

Panics if the divisor is zero.

fn saturating_mul_int(self, rhs: Self::Bits) -> Self[src]

Saturating multiplication by an integer. Returns the product, saturating on overflow.

fn wrapping_neg(self) -> Self[src]

Wrapping negation. Returns the negated value, wrapping on overflow.

fn wrapping_add(self, rhs: Self) -> Self[src]

Wrapping addition. Returns the sum, wrapping on overflow.

fn wrapping_sub(self, rhs: Self) -> Self[src]

Wrapping subtraction. Returns the difference, wrapping on overflow.

fn wrapping_mul(self, rhs: Self) -> Self[src]

Wrapping multiplication. Returns the product, wrapping on overflow.

fn wrapping_div(self, rhs: Self) -> Self[src]

Wrapping division. Returns the quotient, wrapping on overflow.

Panics

Panics if the divisor is zero.

fn wrapping_recip(self) -> Self[src]

Wrapping reciprocal.

Panics

Panics if self is zero.

fn wrapping_mul_add(self, mul: Self, add: Self) -> Self[src]

Wrapping multiply and add. Returns self × mul + add, wrapping on overflow.

fn wrapping_div_euclid(self, rhs: Self) -> Self[src]

Wrapping Euclidean division. Returns the quotient, wrapping on overflow.

Panics

Panics if the divisor is zero.

fn wrapping_mul_int(self, rhs: Self::Bits) -> Self[src]

Wrapping multiplication by an integer. Returns the product, wrapping on overflow.

fn wrapping_div_int(self, rhs: Self::Bits) -> Self[src]

Wrapping division by an integer. Returns the quotient, wrapping on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero.

fn wrapping_div_euclid_int(self, rhs: Self::Bits) -> Self[src]

Wrapping Euclidean division by an integer. Returns the quotient, wrapping on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero.

fn wrapping_rem_euclid_int(self, rhs: Self::Bits) -> Self[src]

Wrapping remainder for Euclidean division by an integer. Returns the remainder, wrapping on overflow.

Panics

Panics if the divisor is zero.

fn wrapping_shl(self, rhs: u32) -> Self[src]

Wrapping shift left. Wraps rhs if rhs ≥ the number of bits, then shifts and returns the number.

fn wrapping_shr(self, rhs: u32) -> Self[src]

Wrapping shift right. Wraps rhs if rhs ≥ the number of bits, then shifts and returns the number.

fn unwrapped_neg(self) -> Self[src]

Unwrapped negation. Returns the negated value, panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_add(self, rhs: Self) -> Self[src]

Unwrapped addition. Returns the sum, panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_sub(self, rhs: Self) -> Self[src]

Unwrapped subtraction. Returns the difference, panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_mul(self, rhs: Self) -> Self[src]

Unwrapped multiplication. Returns the product, panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_div(self, rhs: Self) -> Self[src]

Unwrapped division. Returns the quotient, panicking on overflow.

Panics

Panics if the divisor is zero or if the result does not fit.

fn unwrapped_recip(self) -> Self[src]

Unwrapped reciprocal. Returns reciprocal, panicking on overflow.

Panics

Panics if self is zero or on overflow.

fn unwrapped_mul_add(self, mul: Self, add: Self) -> Self[src]

Unwrapped multiply and add. Returns self × mul + add, panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_div_euclid(self, rhs: Self) -> Self[src]

Unwrapped Euclidean division. Returns the quotient, panicking on overflow.

Panics

Panics if the divisor is zero or if the result does not fit.

fn unwrapped_mul_int(self, rhs: Self::Bits) -> Self[src]

Unwrapped multiplication by an integer. Returns the product, panicking on overflow.

Panics

Panics if the result does not fit.

fn unwrapped_div_int(self, rhs: Self::Bits) -> Self[src]

Unwrapped division by an integer. Returns the quotient, panicking on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero or if the result does not fit.

fn unwrapped_div_euclid_int(self, rhs: Self::Bits) -> Self[src]

Unwrapped Euclidean division by an integer. Returns the quotient, panicking on overflow.

Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero or if the result does not fit.

fn unwrapped_rem_euclid_int(self, rhs: Self::Bits) -> Self[src]

Unwrapped remainder for Euclidean division by an integer. Returns the remainder, panicking on overflow.

Panics

Panics if the divisor is zero or if the result does not fit.

fn unwrapped_shl(self, rhs: u32) -> Self[src]

Unwrapped shift left. Panics if rhs ≥ the number of bits.

Panics

Panics if rhs ≥ the number of bits.

fn unwrapped_shr(self, rhs: u32) -> Self[src]

Unwrapped shift right. Panics if rhs ≥ the number of bits.

Panics

Panics if rhs ≥ the number of bits.

fn overflowing_neg(self) -> (Self, bool)[src]

Overflowing negation.

Returns a tuple of the negated value and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_add(self, rhs: Self) -> (Self, bool)[src]

Overflowing addition.

Returns a tuple of the sum and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_sub(self, rhs: Self) -> (Self, bool)[src]

Overflowing subtraction.

Returns a tuple of the difference and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_mul(self, rhs: Self) -> (Self, bool)[src]

Overflowing multiplication.

Returns a tuple of the product and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_div(self, rhs: Self) -> (Self, bool)[src]

Overflowing division.

Returns a tuple of the quotient and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Panics

Panics if the divisor is zero.

fn overflowing_recip(self) -> (Self, bool)[src]

Overflowing reciprocal.

Returns a tuple of the reciprocal of self and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Panics

Panics if self is zero.

fn overflowing_mul_add(self, mul: Self, add: Self) -> (Self, bool)[src]

Overflowing multiply and add.

Returns a tuple of self × mul + add and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)[src]

Overflowing Euclidean division.

Returns a tuple of the quotient and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Panics

Panics if the divisor is zero.

fn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool)[src]

Overflowing multiplication by an integer.

Returns a tuple of the product and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool)[src]

Overflowing division by an integer.

Returns a tuple of the quotient and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Panics

Panics if the divisor is zero.

fn overflowing_div_euclid_int(self, rhs: Self::Bits) -> (Self, bool)[src]

Overflowing Euclidean division by an integer.

Returns a tuple of the quotient and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Panics

Panics if the divisor is zero.

fn overflowing_rem_euclid_int(self, rhs: Self::Bits) -> (Self, bool)[src]

Overflowing remainder for Euclidean division by an integer.

Returns a tuple of the remainder and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Panics

Panics if the divisor is zero.

fn overflowing_shl(self, rhs: u32) -> (Self, bool)[src]

Overflowing shift left.

Returns a tuple of the shifted value and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

fn overflowing_shr(self, rhs: u32) -> (Self, bool)[src]

Overflowing shift right.

Returns a tuple of the shifted value and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Loading content...

Implementors

impl<Frac: LeEqU8> Fixed for FixedI8<Frac>[src]

type Bits = i8

type Bytes = [u8; 1]

type Frac = Frac

impl<Frac: LeEqU8> Fixed for FixedU8<Frac>[src]

type Bits = u8

type Bytes = [u8; 1]

type Frac = Frac

impl<Frac: LeEqU16> Fixed for FixedI16<Frac>[src]

type Bits = i16

type Bytes = [u8; 2]

type Frac = Frac

impl<Frac: LeEqU16> Fixed for FixedU16<Frac>[src]

type Bits = u16

type Bytes = [u8; 2]

type Frac = Frac

impl<Frac: LeEqU32> Fixed for FixedI32<Frac>[src]

type Bits = i32

type Bytes = [u8; 4]

type Frac = Frac

impl<Frac: LeEqU32> Fixed for FixedU32<Frac>[src]

type Bits = u32

type Bytes = [u8; 4]

type Frac = Frac

impl<Frac: LeEqU64> Fixed for FixedI64<Frac>[src]

type Bits = i64

type Bytes = [u8; 8]

type Frac = Frac

impl<Frac: LeEqU64> Fixed for FixedU64<Frac>[src]

type Bits = u64

type Bytes = [u8; 8]

type Frac = Frac

impl<Frac: LeEqU128> Fixed for FixedI128<Frac>[src]

type Bits = i128

type Bytes = [u8; 16]

type Frac = Frac

impl<Frac: LeEqU128> Fixed for FixedU128<Frac>[src]

type Bits = u128

type Bytes = [u8; 16]

type Frac = Frac

Loading content...