Struct fp::FpU32

source ·
pub struct FpU32<const BITS: u32, const SHIFT: i32>(/* private fields */);
Expand description

#[repr(transparent)] struct containing u32, interpreted as a fixed-point number.

Impelements the trait Fp for fixed-point manipulation.

Implementations§

source§

impl<const B: u32, const S: i32> FpU32<B, S>

source

pub fn into_signed(self) -> FpI32<{ _ }, S>
where [(); { _ }]:,

source§

impl<const BITS: u32, const SHIFT: i32> FpU32<BITS, SHIFT>

source

pub const fn mul_const_bits(val: u32) -> u32

Returns the bit width of the return type from mul_const.

source

pub fn mul_const<const VAL: u32>(self) -> FpU32<{ _ }, SHIFT>

source

pub const fn div_const_bits(val: u32) -> u32

Returns the bit width of the return type from div_const.

source

pub fn div_const<const VAL: u32>(self) -> FpU32<{ _ }, SHIFT>

Trait Implementations§

source§

impl<const B0: u32, const B1: u32, const S: i32> Add<FpU32<B1, S>> for FpU32<B0, S>
where [(); { _ }]:,

Two fixed-point integers with the same raw type and the same shift may be added together. The result has the same raw type and the same shift. The result has 1 more bit than the number of bits in the wider of the two inputs.

§

type Output = FpU32<{ max(B0, B1) + 1 }, S>

The resulting type after applying the + operator.
source§

fn add(self: FpU32<B0, S>, other: FpU32<B1, S>) -> Self::Output

Performs the + operation. Read more
source§

impl<const BITS: u32, const SHIFT: i32> Clone for FpU32<BITS, SHIFT>

source§

fn clone(&self) -> FpU32<BITS, SHIFT>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const BITS: u32, const SHIFT: i32> Debug for FpU32<BITS, SHIFT>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpI32<B1, S1>> for FpU32<B0, S0>
where [(); { _ }]:,

§

type Output = FpI32<{ B0 + 1 }, { S0 - S1 }>

The resulting type after applying the / operator.
source§

fn div(self: FpU32<B0, S0>, other: FpI32<B1, S1>) -> Self::Output

Performs the / operation. Read more
source§

impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpU32<B1, S1>> for FpI32<B0, S0>
where [(); { _ }]:,

§

type Output = FpI32<B0, { S0 - S1 }>

The resulting type after applying the / operator.
source§

fn div(self: FpI32<B0, S0>, other: FpU32<B1, S1>) -> Self::Output

Performs the / operation. Read more
source§

impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpU32<B1, S1>> for FpU32<B0, S0>
where [(); { _ }]:,

§

type Output = FpU32<{ B0 + Self::SIGNED as u32 }, { S0 - S1 }>

The resulting type after applying the / operator.
source§

fn div(self: FpU32<B0, S0>, other: FpU32<B1, S1>) -> Self::Output

Performs the / operation. Read more
source§

impl<const BITS: u32, const SHIFT: i32> Fp for FpU32<BITS, SHIFT>

source§

unsafe fn from_f32_unchecked(val: f32) -> Self

May cause a divide by zero error if SHIFT is extremely small.

source§

unsafe fn from_f64_unchecked(val: f64) -> Self

May cause a divide by zero error if SHIFT is extremely small.

source§

fn into_f32(self) -> f32

Panics when the logical value could exceed f32::MAX.

source§

fn into_f64(self) -> f64

Panics when the logical value could exceed f64::MAX.

§

type Raw = u32

The underlying (“raw”) representation of this fixed-point number. Typically this is a primitive integer type, e.g. i64.
§

type Output<const B: u32, const S: i32> = FpU32<B, S>

The type that this fixed point number will become after BITS and/or SHIFT are changed by an operation. Typically this is one of the Fp* structs, e.g. FpI64.
source§

const BITS: u32 = _

BITS is the number of least-significant bits which are permitted to vary. The Raw::BITS - BITS high-order bits must be zero (for unsigned Raw) or the same as the high bit of the lower BITS bits (for signed Raw).
source§

const SHIFT: i32 = SHIFT

SHIFT sets the scaling factor between the stored raw value (of type Raw) and the “logical” value with it represents. The logical value of this fixed-point number is equal to the raw value divided by 2.pow(SHIFT). Read more
source§

const MIN: Self = _

Minimum possible value of this type.
source§

const MAX: Self = _

Maximum possible value of this type.
source§

const SIGNED: bool = false

Whether this type is signed. (If false, it’s unsigned.)
source§

unsafe fn new_unchecked(val: u32) -> Self

Interpret the provided raw value as a fixed-point number of type Self. Unsafe: no bounds checking is performed; the caller must ensure that the result lies between Self::MIN and Self::MAX. It is almost always better to use .new().unwrap() instead of this function, so that an out-of-bounds value panics with a reasonable message instead of propagating undefined behavior.
source§

fn raw(self) -> u32

Return the raw value which internally represents this fixed-point number.
source§

fn new(val: Self::Raw) -> Result<Self, RangeError>

Interpret the provided raw value as a fixed-point number of type Self, or return a RangeError if it is too small or too large to represent a valid instance of Self.
source§

fn from_f32(val: f32) -> Result<Self, RangeError>

Return the fixed-point number of type Self which has a logical value of val, or return a RangeError if val is too small or too large to be represented by Self.
source§

fn from_f64(val: f64) -> Result<Self, RangeError>

Return the fixed-point number of type Self which has a logical value of val, or return a RangeError if val is too small or too large to be represented by Self.
source§

fn from_fp<T: Fp, F: Fp<Raw = T>>(val: F) -> Self
where Self::Raw: TryFrom<T>,

Return the fixed-point number of type Self which has the same logical value as val. F and Self must have the same shift and signedness. Self must have at least as many bits as F.
source§

fn into_fp<T, F: Fp<Raw = T>>(self) -> F
where T: TryFrom<Self::Raw> + Fp,

Return the fixed-point number of type F which has the same logical value as self. F and Self must have the same shift and signedness. F must have at least as many bits as Self.
source§

fn add_bits<const N: u32>(self) -> Self::Output<{ _ }, { Self::SHIFT }>
where [(); { _ }]:,

Increase the number of bits used to represent this value. Both the raw and logical values are unchanged. This is a type system operation only. Compilation will fail if the new number of bits is too large for the raw type.
source§

fn set_bits<const N: u32>( self ) -> Result<Self::Output<N, { Self::SHIFT }>, RangeError>

Set the number of bits used to represent this value. The value is checked at runtime to ensure it is in range for the new number of bits. If succesful, both the raw and logical values are unchanged.
source§

unsafe fn set_bits_unchecked<const N: u32>( self ) -> Self::Output<N, { Self::SHIFT }>

Set the number of bits used to represent this value. Unsafe: no bounds checking is performed; the caller must ensure that the value fits within the new number of bits. It is almost always better to call .set_bits().unwrap() instead, so that an out-of-bounds value panics with a reasonable message instead of propagating undefined behavior.
source§

fn saturate<const N: u32>(self) -> Self::Output<N, { Self::SHIFT }>

Set the number of bits used to represent this value, saturating in case of overflow.
source§

fn logical_shl<const N: i32>(self) -> Self::Output<{ Self::BITS }, { _ }>
where [(); { _ }]:,

Shift the logical value of this number left by N bits. (N may be negative for a right shift). This is a type system operation only; the raw value is unchanged. The logical value is multiplied by 2^N.
source§

fn logical_shr<const N: i32>(self) -> Self::Output<{ Self::BITS }, { _ }>
where [(); { _ }]:,

Shift the logical value of this number right by N bits. (N may be negative for a left shift). This is a type system operation only; the raw value is unchanged. The logical value is divided by 2^N.
source§

fn raw_shl<const N: u32>(self) -> Self::Output<{ _ }, { _ }>
where [(); { _ }]:,

Shift the raw value of this number left by N bits. Compiles to a left shift. The logical value is unchanged.
source§

fn raw_shr<const N: u32>(self) -> Self::Output<{ _ }, { _ }>
where [(); { _ }]:,

Shift the raw value of this number right by N bits. Compiles to a right shift. The logical value is unchanged, except for truncation of the N least-significant bits.
source§

impl From<FpU32<{ <$T>::BITS }, 0>> for u32

A fixed-point number with no shift and maximum bit width is equivalent to its internal (“raw”) representation.

source§

fn from(val: FpU32<{ u32::BITS }, 0>) -> Self

Converts to this type from the input type.
source§

impl From<u32> for FpU32<{ u32::BITS }, 0>

A fixed-point number with no shift and maximum bit width is equivalent to its internal (“raw”) representation.

source§

fn from(val: u32) -> Self

Converts to this type from the input type.
source§

impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpI32<B1, S1>> for FpU32<B0, S0>
where [(); { _ }]:,

§

type Output = FpI32<{ B0 + B1 }, { S0 + S1 }>

The resulting type after applying the * operator.
source§

fn mul(self: FpU32<B0, S0>, other: FpI32<B1, S1>) -> Self::Output

Performs the * operation. Read more
source§

impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpU32<B1, S1>> for FpI32<B0, S0>
where [(); { _ }]:,

§

type Output = FpI32<{ B0 + B1 }, { S0 + S1 }>

The resulting type after applying the * operator.
source§

fn mul(self: FpI32<B0, S0>, other: FpU32<B1, S1>) -> Self::Output

Performs the * operation. Read more
source§

impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpU32<B1, S1>> for FpU32<B0, S0>
where [(); { _ }]:,

§

type Output = FpU32<{ B0 + B1 }, { S0 + S1 }>

The resulting type after applying the * operator.
source§

fn mul(self: FpU32<B0, S0>, other: FpU32<B1, S1>) -> Self::Output

Performs the * operation. Read more
source§

impl<const B: u32, const S: i32> Neg for FpU32<B, S>
where [(); { _ }]:,

§

type Output = FpI32<{ B + 1 }, S>

The resulting type after applying the - operator.
source§

fn neg(self: FpU32<B, S>) -> Self::Output

Performs the unary - operation. Read more
source§

impl<const BITS: u32, const SHIFT: i32> Ord for FpU32<BITS, SHIFT>

source§

fn cmp(&self, other: &FpU32<BITS, SHIFT>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<const BITS: u32, const SHIFT: i32> PartialEq for FpU32<BITS, SHIFT>

source§

fn eq(&self, other: &FpU32<BITS, SHIFT>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const BITS: u32, const SHIFT: i32> PartialOrd for FpU32<BITS, SHIFT>

source§

fn partial_cmp(&self, other: &FpU32<BITS, SHIFT>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<const B0: u32, const B1: u32, const S: i32> Sub<FpU32<B1, S>> for FpU32<B0, S>
where [(); { _ }]:,

Two fixed-point integers with the same raw type and the same shift may be subtracted. The result is always signed, even if the inputs were unsigned. The result has the same shift as the inputs, and 1 more bit than the number of bits in the wider of the two inputs.

§

type Output = FpI32<{ max(B0, B1) + 1 }, S>

The resulting type after applying the - operator.
source§

fn sub(self: FpU32<B0, S>, other: FpU32<B1, S>) -> Self::Output

Performs the - operation. Read more
source§

impl<const BITS: u32, const SHIFT: i32> Copy for FpU32<BITS, SHIFT>

source§

impl<const BITS: u32, const SHIFT: i32> Eq for FpU32<BITS, SHIFT>

source§

impl<const BITS: u32, const SHIFT: i32> StructuralPartialEq for FpU32<BITS, SHIFT>

Auto Trait Implementations§

§

impl<const BITS: u32, const SHIFT: i32> Freeze for FpU32<BITS, SHIFT>

§

impl<const BITS: u32, const SHIFT: i32> RefUnwindSafe for FpU32<BITS, SHIFT>

§

impl<const BITS: u32, const SHIFT: i32> Send for FpU32<BITS, SHIFT>

§

impl<const BITS: u32, const SHIFT: i32> Sync for FpU32<BITS, SHIFT>

§

impl<const BITS: u32, const SHIFT: i32> Unpin for FpU32<BITS, SHIFT>

§

impl<const BITS: u32, const SHIFT: i32> UnwindSafe for FpU32<BITS, SHIFT>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.