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

pub trait Fixed where
    Self: Copy + Default + Hash + Ord,
    Self: Debug + Display + Binary + Octal + LowerHex + UpperHex,
    Self: FromFixed + ToFixed + Fixed,
    Self: Add<Output = Self> + Sub<Output = Self> + Mul<Output = Self> + Div<Output = Self>,
    Self: BitAnd<Output = Self> + BitOr<Output = Self> + BitXor<Output = Self>,
    Self: Not<Output = Self> + Shl<u32, Output = Self> + Shr<u32, Output = Self>,
    Self: AddAssign + SubAssign + MulAssign + DivAssign,
    Self: BitAndAssign + BitOrAssign + BitXorAssign + ShlAssign<u32> + 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
{ type Bits; fn min_value() -> Self;
fn max_value() -> Self;
fn int_nbits() -> u32;
fn frac_nbits() -> u32;
fn from_bits(bits: Self::Bits) -> Self;
fn to_bits(self) -> Self::Bits;
fn from_int<I: Int>(val: I) -> Self;
fn to_int<I: Int>(self) -> I;
fn from_float<F: Float>(val: F) -> Self;
fn to_float<F: Float>(self) -> F;
fn checked_from_int<I: Int>(val: I) -> Option<Self>;
fn checked_to_int<I: Int>(self) -> Option<I>;
fn checked_from_float<F: Float>(val: F) -> Option<Self>;
fn saturating_from_int<I: Int>(val: I) -> Self;
fn saturating_to_int<I: Int>(self) -> I;
fn saturating_from_float<F: Float>(val: F) -> Self;
fn wrapping_from_int<I: Int>(val: I) -> Self;
fn wrapping_to_int<I: Int>(self) -> I;
fn wrapping_from_float<F: Float>(val: F) -> Self;
fn overflowing_from_int<I: Int>(val: I) -> (Self, bool);
fn overflowing_to_int<I: Int>(self) -> (I, bool);
fn overflowing_from_float<F: Float>(val: F) -> (Self, bool);
fn int(self) -> Self;
fn frac(self) -> Self;
fn ceil(self) -> Self;
fn floor(self) -> Self;
fn round(self) -> Self;
fn checked_ceil(self) -> Option<Self>;
fn checked_floor(self) -> Option<Self>;
fn checked_round(self) -> Option<Self>;
fn saturating_ceil(self) -> Self;
fn saturating_floor(self) -> Self;
fn saturating_round(self) -> Self;
fn wrapping_ceil(self) -> Self;
fn wrapping_floor(self) -> Self;
fn wrapping_round(self) -> Self;
fn overflowing_ceil(self) -> (Self, bool);
fn overflowing_floor(self) -> (Self, bool);
fn overflowing_round(self) -> (Self, bool);
fn count_ones(self) -> u32;
fn count_zeros(self) -> u32;
fn leading_zeros(self) -> u32;
fn trailing_zeros(self) -> u32;
fn rotate_left(self, n: u32) -> Self;
fn rotate_right(self, n: u32) -> Self;
fn mul_int(self, rhs: Self::Bits) -> Self;
fn div_int(self, rhs: Self::Bits) -> Self;
fn rem_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_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_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_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_mul_int(self, rhs: Self::Bits) -> Self;
fn wrapping_div_int(self, rhs: Self::Bits) -> Self;
fn wrapping_rem_int(self, rhs: Self::Bits) -> Self;
fn wrapping_shl(self, rhs: u32) -> Self;
fn wrapping_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_mul_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_rem_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 common methods to all fixed-point numbers.

Associated Types

type Bits

The primitive integer underlying type.

Loading content...

Required methods

fn min_value() -> Self

Returns the smallest value that can be represented.

fn max_value() -> Self

Returns the largest value that can be represented.

fn int_nbits() -> u32

Returns the number of integer bits.

fn frac_nbits() -> u32

Returns the number of fractional bits.

fn from_bits(bits: Self::Bits) -> Self

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

fn to_bits(self) -> Self::Bits

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

fn from_int<I: Int>(val: I) -> Self

Creates a fixed-point number from an integer.

Returns the same value as val.to_fixed().

fn to_int<I: Int>(self) -> I

Converts a fixed-point number to an integer.

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

fn from_float<F: Float>(val: F) -> Self

Creates a fixed-point number from a floating-point number.

Returns the same value as val.to_fixed().

fn to_float<F: Float>(self) -> F

Converts a fixed-point number to a floating-point number.

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

fn checked_from_int<I: Int>(val: I) -> Option<Self>

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

Returns the same value as val.checked_to_fixed().

fn checked_to_int<I: Int>(self) -> Option<I>

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

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

fn checked_from_float<F: Float>(val: F) -> Option<Self>

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

Returns the same value as val.checked_to_fixed().

fn saturating_from_int<I: Int>(val: I) -> Self

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

Returns the same value as val.saturating_to_fixed().

fn saturating_to_int<I: Int>(self) -> I

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

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

fn saturating_from_float<F: Float>(val: F) -> Self

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

Returns the same value as val.saturating_to_fixed().

fn wrapping_from_int<I: Int>(val: I) -> Self

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

Returns the same value as val.wrapping_to_fixed().

fn wrapping_to_int<I: Int>(self) -> I

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

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

fn wrapping_from_float<F: Float>(val: F) -> Self

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

Returns the same value as val.wrapping_to_fixed().

fn overflowing_from_int<I: Int>(val: I) -> (Self, bool)

Creates a fixed-point number from an integer.

Returns the same value as val.overflowing_to_fixed().

fn overflowing_to_int<I: Int>(self) -> (I, bool)

Converts a fixed-point number to an integer.

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

fn overflowing_from_float<F: Float>(val: F) -> (Self, bool)

Creates a fixed-point number from a floating-point number.

Returns the same value as val.overflowing_to_fixed().

fn int(self) -> Self

Returns the integer part.

fn frac(self) -> Self

Returns the fractional part.

fn ceil(self) -> Self

Rounds to the next integer towards +∞.

fn floor(self) -> Self

Rounds to the next integer towards −∞.

fn round(self) -> Self

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

fn checked_ceil(self) -> Option<Self>

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

fn checked_floor(self) -> Option<Self>

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

fn checked_round(self) -> Option<Self>

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

fn saturating_ceil(self) -> Self

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

fn saturating_floor(self) -> Self

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

fn saturating_round(self) -> Self

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

fn wrapping_ceil(self) -> Self

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

fn wrapping_floor(self) -> Self

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

fn wrapping_round(self) -> Self

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

fn overflowing_ceil(self) -> (Self, bool)

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)

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)

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 count_ones(self) -> u32

Returns the number of ones in the binary representation.

fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation.

fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation.

fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation.

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

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

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

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

fn mul_int(self, rhs: Self::Bits) -> Self

Multiplication by an integer.

fn div_int(self, rhs: Self::Bits) -> Self

Division by an integer.

fn rem_int(self, rhs: Self::Bits) -> Self

Remainder for division by an integer.

fn checked_neg(self) -> Option<Self>

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

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

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

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

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

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

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

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

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

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

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

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

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>

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_shl(self, rhs: u32) -> Option<Self>

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

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

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

fn saturating_neg(self) -> Self

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

fn saturating_add(self, rhs: Self) -> Self

Saturating addition. Returns the sum, saturating on overflow.

fn saturating_sub(self, rhs: Self) -> Self

Saturating subtraction. Returns the difference, saturating on overflow.

fn saturating_mul(self, rhs: Self) -> Self

Saturating multiplication. Returns the product, saturating on overflow.

fn saturating_div(self, rhs: Self) -> Self

Saturating division. Returns the quotient, saturating on overflow.

Panics

Panics if the divisor is zero.

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

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

fn wrapping_neg(self) -> Self

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

fn wrapping_add(self, rhs: Self) -> Self

Wrapping addition. Returns the sum, wrapping on overflow.

fn wrapping_sub(self, rhs: Self) -> Self

Wrapping subtraction. Returns the difference, wrapping on overflow.

fn wrapping_mul(self, rhs: Self) -> Self

Wrapping multiplication. Returns the product, wrapping on overflow.

fn wrapping_div(self, rhs: Self) -> Self

Wrapping division. Returns the quotient, wrapping on overflow.

Panics

Panics if the divisor is zero.

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

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

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

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_rem_int(self, rhs: Self::Bits) -> Self

Wrapping fixed-point remainder for division by an integer. Returns the remainder, wrapping on overflow.

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

Panics

Panics if the divisor is zero.

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

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

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

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

fn overflowing_neg(self) -> (Self, bool)

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)

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)

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)

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)

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_mul_int(self, rhs: Self::Bits) -> (Self, bool)

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)

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_rem_int(self, rhs: Self::Bits) -> (Self, bool)

Overflowing fixed-point remainder for 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. Overflow can only occur when dividing the minimum value by −1.

Panics

Panics if the divisor is zero.

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

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)

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> Fixed for FixedI128<Frac> where
    Frac: Unsigned + IsLessOrEqual<U128, Output = True>, 
[src]

type Bits = i128

impl<Frac> Fixed for FixedI16<Frac> where
    Frac: Unsigned + IsLessOrEqual<U16, Output = True>, 
[src]

type Bits = i16

impl<Frac> Fixed for FixedI32<Frac> where
    Frac: Unsigned + IsLessOrEqual<U32, Output = True>, 
[src]

type Bits = i32

impl<Frac> Fixed for FixedI64<Frac> where
    Frac: Unsigned + IsLessOrEqual<U64, Output = True>, 
[src]

type Bits = i64

impl<Frac> Fixed for FixedI8<Frac> where
    Frac: Unsigned + IsLessOrEqual<U8, Output = True>, 
[src]

type Bits = i8

impl<Frac> Fixed for FixedU128<Frac> where
    Frac: Unsigned + IsLessOrEqual<U128, Output = True>, 
[src]

type Bits = u128

impl<Frac> Fixed for FixedU16<Frac> where
    Frac: Unsigned + IsLessOrEqual<U16, Output = True>, 
[src]

type Bits = u16

impl<Frac> Fixed for FixedU32<Frac> where
    Frac: Unsigned + IsLessOrEqual<U32, Output = True>, 
[src]

type Bits = u32

impl<Frac> Fixed for FixedU64<Frac> where
    Frac: Unsigned + IsLessOrEqual<U64, Output = True>, 
[src]

type Bits = u64

impl<Frac> Fixed for FixedU8<Frac> where
    Frac: Unsigned + IsLessOrEqual<U8, Output = True>, 
[src]

type Bits = u8

Loading content...