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>
impl<const B: u32, const S: i32> FpU32<B, S>
pub fn into_signed(self) -> FpI32<{ _ }, S>
source§impl<const BITS: u32, const SHIFT: i32> FpU32<BITS, SHIFT>
impl<const BITS: u32, const SHIFT: i32> FpU32<BITS, SHIFT>
sourcepub const fn mul_const_bits(val: u32) -> u32
pub const fn mul_const_bits(val: u32) -> u32
Returns the bit width of the return type from mul_const
.
pub fn mul_const<const VAL: u32>(self) -> FpU32<{ _ }, SHIFT>
sourcepub const fn div_const_bits(val: u32) -> u32
pub const fn div_const_bits(val: u32) -> u32
Returns the bit width of the return type from div_const
.
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>
impl<const B0: u32, const B1: u32, const S: i32> Add<FpU32<B1, S>> for FpU32<B0, S>
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.
source§impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpI32<B1, S1>> for FpU32<B0, S0>
impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpI32<B1, S1>> for FpU32<B0, S0>
source§impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpU32<B1, S1>> for FpI32<B0, S0>
impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpU32<B1, S1>> for FpI32<B0, S0>
source§impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpU32<B1, S1>> for FpU32<B0, S0>
impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Div<FpU32<B1, S1>> for FpU32<B0, S0>
source§impl<const BITS: u32, const SHIFT: i32> Fp for FpU32<BITS, SHIFT>
impl<const BITS: u32, const SHIFT: i32> Fp for FpU32<BITS, SHIFT>
source§unsafe fn from_f32_unchecked(val: f32) -> Self
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
unsafe fn from_f64_unchecked(val: f64) -> Self
May cause a divide by zero error if SHIFT
is extremely small.
§type Raw = u32
type Raw = u32
i64
.§type Output<const B: u32, const S: i32> = FpU32<B, S>
type Output<const B: u32, const S: i32> = FpU32<B, S>
BITS
and/or SHIFT
are changed by an operation. Typically this is one of the Fp*
structs, e.g.
FpI64
.source§const BITS: u32 = _
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
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 moresource§unsafe fn new_unchecked(val: u32) -> Self
unsafe fn new_unchecked(val: u32) -> Self
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 new(val: Self::Raw) -> Result<Self, RangeError>
fn new(val: Self::Raw) -> Result<Self, RangeError>
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>
fn from_f32(val: f32) -> Result<Self, RangeError>
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>
fn from_f64(val: f64) -> Result<Self, RangeError>
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
fn from_fp<T: Fp, F: Fp<Raw = T>>(val: F) -> Self
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
fn into_fp<T, F: Fp<Raw = T>>(self) -> F
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 }>
fn add_bits<const N: u32>(self) -> Self::Output<{ _ }, { Self::SHIFT }>
source§fn set_bits<const N: u32>(
self
) -> Result<Self::Output<N, { Self::SHIFT }>, RangeError>
fn set_bits<const N: u32>( self ) -> Result<Self::Output<N, { Self::SHIFT }>, RangeError>
source§unsafe fn set_bits_unchecked<const N: u32>(
self
) -> Self::Output<N, { Self::SHIFT }>
unsafe fn set_bits_unchecked<const N: u32>( self ) -> Self::Output<N, { Self::SHIFT }>
.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 }>
fn saturate<const N: u32>(self) -> Self::Output<N, { Self::SHIFT }>
source§fn logical_shl<const N: i32>(self) -> Self::Output<{ Self::BITS }, { _ }>
fn logical_shl<const N: i32>(self) -> Self::Output<{ Self::BITS }, { _ }>
source§fn logical_shr<const N: i32>(self) -> Self::Output<{ Self::BITS }, { _ }>
fn logical_shr<const N: i32>(self) -> Self::Output<{ Self::BITS }, { _ }>
source§impl From<FpU32<{ <$T>::BITS }, 0>> for u32
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§impl From<u32> for FpU32<{ u32::BITS }, 0>
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§impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpI32<B1, S1>> for FpU32<B0, S0>
impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpI32<B1, S1>> for FpU32<B0, S0>
source§impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpU32<B1, S1>> for FpI32<B0, S0>
impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpU32<B1, S1>> for FpI32<B0, S0>
source§impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpU32<B1, S1>> for FpU32<B0, S0>
impl<const B0: u32, const B1: u32, const S0: i32, const S1: i32> Mul<FpU32<B1, S1>> for FpU32<B0, S0>
source§impl<const BITS: u32, const SHIFT: i32> Ord for FpU32<BITS, SHIFT>
impl<const BITS: u32, const SHIFT: i32> Ord for FpU32<BITS, SHIFT>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<const BITS: u32, const SHIFT: i32> PartialEq for FpU32<BITS, SHIFT>
impl<const BITS: u32, const SHIFT: i32> PartialEq for FpU32<BITS, SHIFT>
source§impl<const BITS: u32, const SHIFT: i32> PartialOrd for FpU32<BITS, SHIFT>
impl<const BITS: u32, const SHIFT: i32> PartialOrd for FpU32<BITS, SHIFT>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<const B0: u32, const B1: u32, const S: i32> Sub<FpU32<B1, S>> for FpU32<B0, S>
impl<const B0: u32, const B1: u32, const S: i32> Sub<FpU32<B1, S>> for FpU32<B0, S>
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.