pub trait Fixed: Sealedwhere
Self: Debug + Default + Hash + Ord + Contiguous + Pod + TransparentWrapper<Self::Bits> + FromFixed + ToFixed + Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign + Mul<Output = Self> + MulAssign + Rem<Output = Self> + RemAssign + Mul<Self::Bits, Output = Self> + MulAssign<Self::Bits> + Div<Self::Bits, Output = Self> + DivAssign<Self::Bits> + 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 + PartialOrd<i8> + PartialOrd<i16> + PartialOrd<i32> + PartialOrd<i64> + PartialOrd<i128> + PartialOrd<isize> + PartialOrd<u8> + PartialOrd<u16> + PartialOrd<u32> + PartialOrd<u64> + PartialOrd<u128> + PartialOrd<usize> + PartialOrd<f16> + PartialOrd<bf16> + PartialOrd<f32> + PartialOrd<f64> + PartialOrd<F128> + FixedOptionalArbitrary + FixedOptionalBorsh + FixedOptionalNum + FixedOptionalSerde,{
type Bits: FixedBits + From<Self::NonZeroBits>;
type NonZeroBits: TryFrom<Self::Bits, Error = TryFromIntError>;
type Signed: FixedSigned;
type Unsigned: FixedUnsigned;
const ZERO: Self;
const TRY_ONE: Option<Self>;
const DELTA: Self;
const MIN: Self;
const MAX: Self;
const IS_SIGNED: bool;
const INT_BITS: i32;
const FRAC_BITS: i32;
Show 143 methods
// Required methods
fn from_bits(bits: Self::Bits) -> Self;
fn to_bits(self) -> Self::Bits;
fn from_be(fixed: Self) -> Self;
fn from_le(fixed: Self) -> Self;
fn to_be(self) -> Self;
fn to_le(self) -> Self;
fn swap_bytes(self) -> Self;
fn from_be_bytes(bytes: [u8; { _ }]) -> Self;
fn from_le_bytes(bytes: [u8; { _ }]) -> Self;
fn from_ne_bytes(bytes: [u8; { _ }]) -> Self;
fn to_be_bytes(self) -> [u8; { _ }];
fn to_le_bytes(self) -> [u8; { _ }];
fn to_ne_bytes(self) -> [u8; { _ }];
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 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 checked_int_log2(self) -> Option<i32>;
fn reverse_bits(self) -> Self;
fn rotate_left(self, n: u32) -> Self;
fn rotate_right(self, n: u32) -> Self;
fn is_zero(self) -> bool;
fn dist(self, other: Self) -> Self;
fn abs_diff(self, other: Self) -> Self::Unsigned;
fn mean(self, other: Self) -> Self;
fn next_multiple_of(self, other: Self) -> Self;
fn mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Self;
fn add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Self;
fn mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
);
fn rem_euclid(self, rhs: Self) -> 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_rem(self, rhs: Self) -> Option<Self>;
fn checked_next_multiple_of(self, other: Self) -> Option<Self>;
fn checked_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Option<Self>;
fn checked_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Option<Self>;
fn checked_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Option<()>;
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_shl(self, rhs: u32) -> Option<Self>;
fn checked_shr(self, rhs: u32) -> Option<Self>;
fn checked_dist(self, other: Self) -> 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_next_multiple_of(self, other: Self) -> Self;
fn saturating_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Self;
fn saturating_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Self;
fn saturating_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
);
fn saturating_mul_int(self, rhs: Self::Bits) -> Self;
fn saturating_div_int(self, rhs: Self::Bits) -> Self;
fn saturating_dist(self, other: Self) -> 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_next_multiple_of(self, other: Self) -> Self;
fn wrapping_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Self;
fn wrapping_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Self;
fn wrapping_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
);
fn wrapping_mul_int(self, rhs: Self::Bits) -> Self;
fn wrapping_div_int(self, rhs: Self::Bits) -> Self;
fn wrapping_shl(self, rhs: u32) -> Self;
fn wrapping_shr(self, rhs: u32) -> Self;
fn wrapping_dist(self, other: Self) -> 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_rem(self, rhs: Self) -> Self;
fn unwrapped_next_multiple_of(self, other: Self) -> Self;
fn unwrapped_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Self;
fn unwrapped_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Self;
fn unwrapped_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
);
fn unwrapped_rem_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_shl(self, rhs: u32) -> Self;
fn unwrapped_shr(self, rhs: u32) -> Self;
fn unwrapped_dist(self, other: Self) -> 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_next_multiple_of(self, other: Self) -> (Self, bool);
fn overflowing_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> (Self, bool);
fn overflowing_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> (Self, bool);
fn overflowing_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> bool;
fn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_shl(self, rhs: u32) -> (Self, bool);
fn overflowing_shr(self, rhs: u32) -> (Self, bool);
fn overflowing_dist(self, other: Self) -> (Self, bool);
// Provided methods
fn get_signed(&self) -> Option<&Self::Signed> { ... }
fn get_unsigned(&self) -> Option<&Self::Unsigned> { ... }
fn get_signed_mut(&mut self) -> Option<&mut Self::Signed> { ... }
fn get_unsigned_mut(&mut self) -> Option<&mut Self::Unsigned> { ... }
}
Expand description
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
#![feature(generic_const_exprs)]
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
.
#![feature(generic_const_exprs)]
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
.
#![feature(generic_const_exprs)]
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.
#![feature(generic_const_exprs)]
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
.)
#![feature(generic_const_exprs)]
use fixed::{traits::Fixed, types::I12F4};
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)));
Required Associated Types§
sourcetype Bits: FixedBits + From<Self::NonZeroBits>
type Bits: FixedBits + From<Self::NonZeroBits>
The primitive integer underlying type.
Examples
#![feature(generic_const_exprs)]
use fixed::{traits::Fixed, types::I16F16};
// 32-bit DELTA is 0x0000_0001_i32
const DELTA_BITS: <I16F16 as Fixed>::Bits = I16F16::DELTA.to_bits();
assert_eq!(DELTA_BITS, 1i32);
sourcetype NonZeroBits: TryFrom<Self::Bits, Error = TryFromIntError>
type NonZeroBits: TryFrom<Self::Bits, Error = TryFromIntError>
sourcetype Signed: FixedSigned
type Signed: FixedSigned
An unsigned fixed-point number type with the same number of integer and
fractional bits as Self
.
If Self
is signed, then Self::Signed
is the same as Self
.
Examples
#![feature(generic_const_exprs)]
use fixed::{
traits::Fixed,
types::{I16F16, U16F16},
};
// I16F16::Signed is I16F16
assert_eq!(<I16F16 as Fixed>::Signed::FRAC_BITS, I16F16::FRAC_BITS);
assert_eq!(<I16F16 as Fixed>::Signed::INT_BITS, I16F16::INT_BITS);
assert_eq!(<I16F16 as Fixed>::Signed::IS_SIGNED, I16F16::IS_SIGNED);
// U16F16::Signed is I16F16
assert_eq!(<U16F16 as Fixed>::Signed::FRAC_BITS, I16F16::FRAC_BITS);
assert_eq!(<U16F16 as Fixed>::Signed::INT_BITS, I16F16::INT_BITS);
assert_eq!(<U16F16 as Fixed>::Signed::IS_SIGNED, I16F16::IS_SIGNED);
sourcetype Unsigned: FixedUnsigned
type Unsigned: FixedUnsigned
An unsigned fixed-point number type with the same number of integer and
fractional bits as Self
.
If Self
is unsigned, then Self::Unsigned
is the same as Self
.
Examples
#![feature(generic_const_exprs)]
use fixed::{
traits::Fixed,
types::{I16F16, U16F16},
};
// I16F16::Unsigned is U16F16
assert_eq!(<I16F16 as Fixed>::Unsigned::FRAC_BITS, U16F16::FRAC_BITS);
assert_eq!(<I16F16 as Fixed>::Unsigned::INT_BITS, U16F16::INT_BITS);
assert_eq!(<I16F16 as Fixed>::Unsigned::IS_SIGNED, U16F16::IS_SIGNED);
// U16F16::Unsigned is U16F16
assert_eq!(<U16F16 as Fixed>::Unsigned::FRAC_BITS, U16F16::FRAC_BITS);
assert_eq!(<U16F16 as Fixed>::Unsigned::INT_BITS, U16F16::INT_BITS);
assert_eq!(<U16F16 as Fixed>::Unsigned::IS_SIGNED, U16F16::IS_SIGNED);
Required Associated Constants§
Required Methods§
sourcefn swap_bytes(self) -> Self
fn swap_bytes(self) -> Self
Reverses the byte order of the fixed-point number.
See also FixedI32::swap_bytes
and
FixedU32::swap_bytes
.
sourcefn from_be_bytes(bytes: [u8; { _ }]) -> Self
fn from_be_bytes(bytes: [u8; { _ }]) -> Self
Creates a fixed-point number from its representation as a byte array in big endian.
See also
FixedI32::from_be_bytes
and
FixedU32::from_be_bytes
.
sourcefn from_le_bytes(bytes: [u8; { _ }]) -> Self
fn from_le_bytes(bytes: [u8; { _ }]) -> Self
Creates a fixed-point number from its representation as a byte array in little endian.
See also
FixedI32::from_le_bytes
and
FixedU32::from_le_bytes
.
sourcefn from_ne_bytes(bytes: [u8; { _ }]) -> Self
fn from_ne_bytes(bytes: [u8; { _ }]) -> Self
Creates a fixed-point number from its representation as a byte array in native endian.
See also
FixedI32::from_ne_bytes
and
FixedU32::from_ne_bytes
.
sourcefn to_be_bytes(self) -> [u8; { _ }]
fn to_be_bytes(self) -> [u8; { _ }]
Returns the memory representation of this fixed-point number as a byte array in big-endian byte order.
See also FixedI32::to_be_bytes
and FixedU32::to_be_bytes
.
sourcefn to_le_bytes(self) -> [u8; { _ }]
fn to_le_bytes(self) -> [u8; { _ }]
Returns the memory representation of this fixed-point number as a byte array in little-endian byte order.
See also FixedI32::to_le_bytes
and FixedU32::to_le_bytes
.
sourcefn to_ne_bytes(self) -> [u8; { _ }]
fn to_ne_bytes(self) -> [u8; { _ }]
Returns the memory representation of this fixed-point number as a byte array in native byte order.
See also FixedI32::to_ne_bytes
and FixedU32::to_ne_bytes
.
sourcefn to_num<Dst: FromFixed>(self) -> Dst
fn to_num<Dst: FromFixed>(self) -> Dst
Converts a fixed-point number to another number.
Returns the same value as
Dst::from_fixed(self)
.
sourcefn checked_from_num<Src: ToFixed>(src: Src) -> Option<Self>
fn checked_from_num<Src: ToFixed>(src: Src) -> Option<Self>
Creates a fixed-point number from another number if it fits,
otherwise returns None
.
Returns the same value as
src.checked_to_fixed()
.
See also
FixedI32::checked_from_num
and
FixedU32::checked_from_num
.
sourcefn checked_to_num<Dst: FromFixed>(self) -> Option<Dst>
fn checked_to_num<Dst: FromFixed>(self) -> Option<Dst>
Converts a fixed-point number to another number if it fits,
otherwise returns None
.
Returns the same value as
Dst::checked_from_fixed(self)
.
See also
FixedI32::checked_to_num
and
FixedU32::checked_to_num
.
sourcefn saturating_from_num<Src: ToFixed>(src: Src) -> Self
fn saturating_from_num<Src: ToFixed>(src: Src) -> Self
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()
.
See also
FixedI32::saturating_from_num
and
FixedU32::saturating_from_num
.
sourcefn saturating_to_num<Dst: FromFixed>(self) -> Dst
fn saturating_to_num<Dst: FromFixed>(self) -> Dst
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)
.
See also
FixedI32::saturating_to_num
and
FixedU32::saturating_to_num
.
sourcefn wrapping_from_num<Src: ToFixed>(src: Src) -> Self
fn wrapping_from_num<Src: ToFixed>(src: Src) -> Self
Creates a fixed-point number from another number, wrapping the value on overflow.
Returns the same value as
src.wrapping_to_fixed()
.
See also
FixedI32::wrapping_from_num
and
FixedU32::wrapping_from_num
.
sourcefn wrapping_to_num<Dst: FromFixed>(self) -> Dst
fn wrapping_to_num<Dst: FromFixed>(self) -> Dst
Converts a fixed-point number to another number, wrapping the value on overflow.
Returns the same value as
Dst::wrapping_from_fixed(self)
.
See also
FixedI32::wrapping_to_num
and
FixedU32::wrapping_to_num
.
sourcefn unwrapped_from_num<Src: ToFixed>(src: Src) -> Self
fn unwrapped_from_num<Src: ToFixed>(src: Src) -> Self
Creates a fixed-point number from another number, panicking on overflow.
Returns the same value as
src.unwrapped_to_fixed()
.
See also
FixedI32::unwrapped_from_num
and
FixedU32::unwrapped_from_num
.
Panics
Panics if the value does not fit.
sourcefn unwrapped_to_num<Dst: FromFixed>(self) -> Dst
fn unwrapped_to_num<Dst: FromFixed>(self) -> Dst
Converts a fixed-point number to another number, panicking on overflow.
Returns the same value as
Dst::unwrapped_from_fixed(self)
.
See also
FixedI32::unwrapped_to_num
and
FixedU32::unwrapped_to_num
.
Panics
Panics if the value does not fit.
sourcefn overflowing_from_num<Src: ToFixed>(src: Src) -> (Self, bool)
fn overflowing_from_num<Src: ToFixed>(src: Src) -> (Self, bool)
Creates a fixed-point number from another number.
Returns the same value as
src.overflowing_to_fixed()
.
See also
FixedI32::overflowing_from_num
and
FixedU32::overflowing_from_num
.
sourcefn overflowing_to_num<Dst: FromFixed>(self) -> (Dst, bool)
fn overflowing_to_num<Dst: FromFixed>(self) -> (Dst, bool)
Converts a fixed-point number to another number.
Returns the same value as
Dst::overflowing_from_fixed(self)
.
See also
FixedI32::overflowing_to_num
and
FixedU32::overflowing_to_num
.
sourcefn round_to_zero(self) -> Self
fn round_to_zero(self) -> Self
Rounds to the next integer towards 0.
See also
FixedI32::round_to_zero
and
FixedU32::round_to_zero
.
sourcefn round_ties_to_even(self) -> Self
fn round_ties_to_even(self) -> Self
Rounds to the nearest integer, with ties rounded to even.
See also
FixedI32::round_ties_to_even
and
FixedU32::round_ties_to_even
.
sourcefn checked_ceil(self) -> Option<Self>
fn checked_ceil(self) -> Option<Self>
Checked ceil. Rounds to the next integer towards +∞, returning
None
on overflow.
See also FixedI32::checked_ceil
and FixedU32::checked_ceil
.
sourcefn checked_floor(self) -> Option<Self>
fn checked_floor(self) -> Option<Self>
Checked floor. Rounds to the next integer towards −∞, returning
None
on overflow.
See also
FixedI32::checked_floor
and
FixedU32::checked_floor
.
sourcefn checked_round(self) -> Option<Self>
fn checked_round(self) -> Option<Self>
Checked round. Rounds to the nearest integer, with ties
rounded away from zero, returning None
on overflow.
See also
FixedI32::checked_round
and
FixedU32::checked_round
.
sourcefn checked_round_ties_to_even(self) -> Option<Self>
fn checked_round_ties_to_even(self) -> Option<Self>
Checked round. Rounds to the nearest integer, with ties
rounded to even, returning None
on overflow.
See also
FixedI32::checked_round_ties_to_even
and
FixedU32::checked_round_ties_to_even
.
sourcefn saturating_ceil(self) -> Self
fn saturating_ceil(self) -> Self
Saturating ceil. Rounds to the next integer towards +∞, saturating on overflow.
See also
FixedI32::saturating_ceil
and
FixedU32::saturating_ceil
.
sourcefn saturating_floor(self) -> Self
fn saturating_floor(self) -> Self
Saturating floor. Rounds to the next integer towards −∞, saturating on overflow.
See also
FixedI32::saturating_floor
and
FixedU32::saturating_floor
.
sourcefn saturating_round(self) -> Self
fn saturating_round(self) -> Self
Saturating round. Rounds to the nearest integer, with ties rounded away from zero, and saturating on overflow.
See also
FixedI32::saturating_round
and
FixedU32::saturating_round
.
sourcefn saturating_round_ties_to_even(self) -> Self
fn saturating_round_ties_to_even(self) -> Self
Saturating round. Rounds to the nearest integer, with ties rounded to_even, and saturating on overflow.
See also
FixedI32::saturating_round_ties_to_even
and
FixedU32::saturating_round_ties_to_even
.
sourcefn wrapping_ceil(self) -> Self
fn wrapping_ceil(self) -> Self
Wrapping ceil. Rounds to the next integer towards +∞, wrapping on overflow.
See also
FixedI32::wrapping_ceil
and
FixedU32::wrapping_ceil
.
sourcefn wrapping_floor(self) -> Self
fn wrapping_floor(self) -> Self
Wrapping floor. Rounds to the next integer towards −∞, wrapping on overflow.
See also
FixedI32::wrapping_floor
and
FixedU32::wrapping_floor
.
sourcefn wrapping_round(self) -> Self
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.
See also
FixedI32::wrapping_round
and
FixedU32::wrapping_round
.
sourcefn wrapping_round_ties_to_even(self) -> Self
fn wrapping_round_ties_to_even(self) -> Self
Wrapping round. Rounds to the next integer to the nearest, with ties rounded to even, and wrapping on overflow.
See also
FixedI32::wrapping_round_ties_to_even
and
FixedU32::wrapping_round_ties_to_even
.
sourcefn unwrapped_ceil(self) -> Self
fn unwrapped_ceil(self) -> Self
Unwrapped ceil. Rounds to the next integer towards +∞, panicking on overflow.
See also
FixedI32::unwrapped_ceil
and
FixedU32::unwrapped_ceil
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_floor(self) -> Self
fn unwrapped_floor(self) -> Self
Unwrapped floor. Rounds to the next integer towards −∞, panicking on overflow.
See also
FixedI32::unwrapped_floor
and
FixedU32::unwrapped_floor
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_round(self) -> Self
fn unwrapped_round(self) -> Self
Unwrapped round. Rounds to the next integer to the nearest, with ties rounded away from zero, and panicking on overflow.
See also
FixedI32::unwrapped_round
and
FixedU32::unwrapped_round
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_round_ties_to_even(self) -> Self
fn unwrapped_round_ties_to_even(self) -> Self
Unwrapped round. Rounds to the next integer to the nearest, with ties rounded to even, and panicking on overflow.
See also
FixedI32::unwrapped_round_ties_to_even
and
FixedU32::unwrapped_round_ties_to_even
.
Panics
Panics if the result does not fit.
sourcefn overflowing_ceil(self) -> (Self, bool)
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.
See also
FixedI32::overflowing_ceil
and
FixedU32::overflowing_ceil
.
sourcefn overflowing_floor(self) -> (Self, bool)
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.
See also
FixedI32::overflowing_floor
and
FixedU32::overflowing_floor
.
sourcefn overflowing_round(self) -> (Self, bool)
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.
See also
FixedI32::overflowing_round
and
FixedU32::overflowing_round
.
sourcefn overflowing_round_ties_to_even(self) -> (Self, bool)
fn overflowing_round_ties_to_even(self) -> (Self, bool)
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.
See also
FixedI32::overflowing_round_ties_to_even
and
FixedU32::overflowing_round_ties_to_even
.
sourcefn count_ones(self) -> u32
fn count_ones(self) -> u32
Returns the number of ones in the binary representation.
See also FixedI32::count_ones
and
FixedU32::count_ones
.
sourcefn count_zeros(self) -> u32
fn count_zeros(self) -> u32
Returns the number of zeros in the binary representation.
See also FixedI32::count_zeros
and FixedU32::count_zeros
.
sourcefn leading_ones(self) -> u32
fn leading_ones(self) -> u32
Returns the number of leading ones in the binary representation.
See also FixedI32::leading_ones
and FixedU32::leading_ones
.
sourcefn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation.
See also
FixedI32::leading_zeros
and
FixedU32::leading_zeros
.
sourcefn trailing_ones(self) -> u32
fn trailing_ones(self) -> u32
Returns the number of trailing ones in the binary representation.
See also
FixedI32::trailing_ones
and
FixedU32::trailing_ones
.
sourcefn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation.
See also
FixedI32::trailing_zeros
and
FixedU32::trailing_zeros
.
sourcefn checked_int_log2(self) -> Option<i32>
fn checked_int_log2(self) -> Option<i32>
Checked integer base-2 logarithm, rounded down. Returns the
logarithm or None
if the fixed-point number is ≤ 0.
See also
FixedI32::checked_int_log2
and
FixedU32::checked_int_log2
.
sourcefn reverse_bits(self) -> Self
fn reverse_bits(self) -> Self
Reverses the order of the bits of the fixed-point number.
See also FixedI32::reverse_bits
and FixedU32::reverse_bits
.
sourcefn rotate_left(self, n: u32) -> Self
fn rotate_left(self, n: u32) -> Self
Shifts to the left by n
bits, wrapping the truncated bits to the right end.
See also FixedI32::rotate_left
and FixedU32::rotate_left
.
sourcefn rotate_right(self, n: u32) -> Self
fn rotate_right(self, n: u32) -> Self
Shifts to the right by n
bits, wrapping the truncated bits to the left end.
See also FixedI32::rotate_right
and FixedU32::rotate_right
.
sourcefn next_multiple_of(self, other: Self) -> Self
fn next_multiple_of(self, other: Self) -> Self
Returns the next multiple of other
.
See also
FixedI32::next_multiple_of
and
FixedU32::next_multiple_of
.
Panics
Panics if other
is zero.
sourcefn mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Self
fn mul_add<const MUL_FRAC: i32>( self, mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>, add: Self ) -> Self
sourcefn add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Self
fn add_prod<const A_FRAC: i32, const B_FRAC: i32>( self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> ) -> Self
sourcefn mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
)
fn mul_acc<const A_FRAC: i32, const B_FRAC: i32>( &mut self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> )
sourcefn rem_euclid(self, rhs: Self) -> Self
fn rem_euclid(self, rhs: Self) -> Self
Remainder for Euclidean division.
See also FixedI32::rem_euclid
and
FixedU32::rem_euclid
.
Panics
Panics if the divisor is zero.
sourcefn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
Checked negation. Returns the negated value, or None
on overflow.
See also FixedI32::checked_neg
and FixedU32::checked_neg
.
sourcefn checked_add(self, rhs: Self) -> Option<Self>
fn checked_add(self, rhs: Self) -> Option<Self>
Checked addition. Returns the sum, or None
on overflow.
See also FixedI32::checked_add
and FixedU32::checked_add
.
sourcefn checked_sub(self, rhs: Self) -> Option<Self>
fn checked_sub(self, rhs: Self) -> Option<Self>
Checked subtraction. Returns the difference, or None
on overflow.
See also FixedI32::checked_sub
and FixedU32::checked_sub
.
sourcefn checked_mul(self, rhs: Self) -> Option<Self>
fn checked_mul(self, rhs: Self) -> Option<Self>
Checked multiplication. Returns the product, or None
on overflow.
See also FixedI32::checked_mul
and FixedU32::checked_mul
.
sourcefn checked_rem(self, rhs: Self) -> Option<Self>
fn checked_rem(self, rhs: Self) -> Option<Self>
Checked remainder. Returns the remainder, or None
if the
divisor is zero.
See also FixedI32::checked_rem
and FixedU32::checked_rem
.
sourcefn checked_next_multiple_of(self, other: Self) -> Option<Self>
fn checked_next_multiple_of(self, other: Self) -> Option<Self>
Checked next multiple of other
. Returns the next multiple, or None
if other
is zero or on overflow.
See also
FixedI32::checked_next_multiple_of
and
FixedU32::checked_next_multiple_of
.
sourcefn checked_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Option<Self>
fn checked_mul_add<const MUL_FRAC: i32>( self, mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>, add: Self ) -> Option<Self>
Checked multiply and add. Returns self
× mul
+ add
, or None
on overflow.
See also
FixedI32::checked_mul_add
and
FixedU32::checked_mul_add
.
sourcefn checked_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Option<Self>
fn checked_add_prod<const A_FRAC: i32, const B_FRAC: i32>( self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> ) -> Option<Self>
Adds self
to the product a
× b
, returning None
on overflow.
See also
FixedI32::checked_add_prod
and
FixedU32::checked_add_prod
.
sourcefn checked_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Option<()>
fn checked_mul_acc<const A_FRAC: i32, const B_FRAC: i32>( &mut self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> ) -> Option<()>
Checked multiply and accumulate. Adds (a
× b
) to self
, or returns
None
on overflow.
See also
FixedI32::checked_mul_acc
and
FixedU32::checked_mul_acc
.
sourcefn checked_rem_euclid(self, rhs: Self) -> Option<Self>
fn checked_rem_euclid(self, rhs: Self) -> Option<Self>
Checked remainder for Euclidean division. Returns the
remainder, or None
if the divisor is zero.
See also
FixedI32::checked_rem_euclid
and
FixedU32::checked_rem_euclid
.
sourcefn checked_mul_int(self, rhs: Self::Bits) -> Option<Self>
fn checked_mul_int(self, rhs: Self::Bits) -> Option<Self>
Checked multiplication by an integer. Returns the product, or
None
on overflow.
See also
FixedI32::checked_mul_int
and
FixedU32::checked_mul_int
.
sourcefn checked_div_int(self, rhs: Self::Bits) -> Option<Self>
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.
See also
FixedI32::checked_div_int
and
FixedU32::checked_div_int
.
sourcefn checked_shl(self, rhs: u32) -> Option<Self>
fn checked_shl(self, rhs: u32) -> Option<Self>
Checked shift left. Returns the shifted number, or None
if
rhs
≥ the number of bits.
See also FixedI32::checked_shl
and FixedU32::checked_shl
.
sourcefn checked_shr(self, rhs: u32) -> Option<Self>
fn checked_shr(self, rhs: u32) -> Option<Self>
Checked shift right. Returns the shifted number, or None
if rhs
≥ the number of bits.
See also FixedI32::checked_shr
and FixedU32::checked_shr
.
sourcefn checked_dist(self, other: Self) -> Option<Self>
fn checked_dist(self, other: Self) -> Option<Self>
Checked distance. Returns the distance from self
to other
, or
None
on overflow.
See also FixedI32::checked_dist
and FixedU32::checked_dist
.
sourcefn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
Saturated negation. Returns the negated value, saturating on overflow.
See also
FixedI32::saturating_neg
and
FixedU32::saturating_neg
.
sourcefn saturating_add(self, rhs: Self) -> Self
fn saturating_add(self, rhs: Self) -> Self
Saturating addition. Returns the sum, saturating on overflow.
See also
FixedI32::saturating_add
and
FixedU32::saturating_add
.
sourcefn saturating_sub(self, rhs: Self) -> Self
fn saturating_sub(self, rhs: Self) -> Self
Saturating subtraction. Returns the difference, saturating on overflow.
See also
FixedI32::saturating_sub
and
FixedU32::saturating_sub
.
sourcefn saturating_mul(self, rhs: Self) -> Self
fn saturating_mul(self, rhs: Self) -> Self
Saturating multiplication. Returns the product, saturating on overflow.
See also
FixedI32::saturating_mul
and
FixedU32::saturating_mul
.
sourcefn saturating_next_multiple_of(self, other: Self) -> Self
fn saturating_next_multiple_of(self, other: Self) -> Self
Saturating next multiple of other
.
See also
FixedI32::saturating_next_multiple_of
and
FixedU32::saturating_next_multiple_of
.
Panics
Panics if other
is zero.
sourcefn saturating_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Self
fn saturating_mul_add<const MUL_FRAC: i32>( self, mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>, add: Self ) -> Self
Saturating multiply and add. Returns self
× mul
+ add
, saturating on overflow.
See also
FixedI32::saturating_mul_add
and
FixedU32::saturating_mul_add
.
sourcefn saturating_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Self
fn saturating_add_prod<const A_FRAC: i32, const B_FRAC: i32>( self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> ) -> Self
Adds self
to the product a
× b
, saturating on overflow.
See also
FixedI32::saturating_add_prod
and
FixedU32::saturating_add_prod
.
sourcefn saturating_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
)
fn saturating_mul_acc<const A_FRAC: i32, const B_FRAC: i32>( &mut self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> )
Saturating multiply and add. Adds (a
× b
) to self
, saturating on overflow.
See also
FixedI32::saturating_mul_acc
and
FixedU32::saturating_mul_acc
.
sourcefn saturating_mul_int(self, rhs: Self::Bits) -> Self
fn saturating_mul_int(self, rhs: Self::Bits) -> Self
Saturating multiplication by an integer. Returns the product, saturating on overflow.
See also
FixedI32::saturating_mul_int
and
FixedU32::saturating_mul_int
.
sourcefn saturating_div_int(self, rhs: Self::Bits) -> Self
fn saturating_div_int(self, rhs: Self::Bits) -> Self
Saturating division by an integer. Returns the quotient, saturating on overflow.
Overflow can only occur when dividing the minimum value by −1.
See also
FixedI32::saturating_div_int
and
FixedU32::saturating_div_int
.
Panics
Panics if the divisor is zero.
sourcefn saturating_dist(self, other: Self) -> Self
fn saturating_dist(self, other: Self) -> Self
Saturating distance. Returns the distance from self
to other
,
saturating on overflow.
See also
FixedI32::saturating_dist
and
FixedU32::saturating_dist
.
sourcefn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
Wrapping negation. Returns the negated value, wrapping on overflow.
See also FixedI32::wrapping_neg
and FixedU32::wrapping_neg
.
sourcefn wrapping_add(self, rhs: Self) -> Self
fn wrapping_add(self, rhs: Self) -> Self
Wrapping addition. Returns the sum, wrapping on overflow.
See also FixedI32::wrapping_add
and FixedU32::wrapping_add
.
sourcefn wrapping_sub(self, rhs: Self) -> Self
fn wrapping_sub(self, rhs: Self) -> Self
Wrapping subtraction. Returns the difference, wrapping on overflow.
See also FixedI32::wrapping_sub
and FixedU32::wrapping_sub
.
sourcefn wrapping_mul(self, rhs: Self) -> Self
fn wrapping_mul(self, rhs: Self) -> Self
Wrapping multiplication. Returns the product, wrapping on overflow.
See also FixedI32::wrapping_mul
and FixedU32::wrapping_mul
.
sourcefn wrapping_next_multiple_of(self, other: Self) -> Self
fn wrapping_next_multiple_of(self, other: Self) -> Self
Wrapping next multiple of other
.
See also
FixedI32::wrapping_next_multiple_of
and
FixedU32::wrapping_next_multiple_of
.
Panics
Panics if other
is zero.
sourcefn wrapping_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Self
fn wrapping_mul_add<const MUL_FRAC: i32>( self, mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>, add: Self ) -> Self
Wrapping multiply and add. Returns self
× mul
+ add
, wrapping on overflow.
See also
FixedI32::wrapping_mul_add
and
FixedU32::wrapping_mul_add
.
sourcefn wrapping_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Self
fn wrapping_add_prod<const A_FRAC: i32, const B_FRAC: i32>( self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> ) -> Self
Adds self
to the product a
× b
, wrapping on overflow.
See also
FixedI32::wrapping_add_prod
and
FixedU32::wrapping_add_prod
.
sourcefn wrapping_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
)
fn wrapping_mul_acc<const A_FRAC: i32, const B_FRAC: i32>( &mut self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> )
Wrapping multiply and accumulate. Adds (a
× b
) to self
, wrapping on overflow.
See also
FixedI32::wrapping_mul_acc
and
FixedU32::wrapping_mul_acc
.
sourcefn wrapping_mul_int(self, rhs: Self::Bits) -> Self
fn wrapping_mul_int(self, rhs: Self::Bits) -> Self
Wrapping multiplication by an integer. Returns the product, wrapping on overflow.
See also
FixedI32::wrapping_mul_int
and
FixedU32::wrapping_mul_int
.
sourcefn wrapping_div_int(self, rhs: Self::Bits) -> Self
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.
See also
FixedI32::wrapping_div_int
and
FixedU32::wrapping_div_int
.
Panics
Panics if the divisor is zero.
sourcefn wrapping_shl(self, rhs: u32) -> Self
fn wrapping_shl(self, rhs: u32) -> Self
Wrapping shift left. Wraps rhs
if rhs
≥ the number of
bits, then shifts and returns the number.
See also FixedI32::wrapping_shl
and FixedU32::wrapping_shl
.
sourcefn wrapping_shr(self, rhs: u32) -> Self
fn wrapping_shr(self, rhs: u32) -> Self
Wrapping shift right. Wraps rhs
if rhs
≥ the number of
bits, then shifts and returns the number.
See also FixedI32::wrapping_shr
and FixedU32::wrapping_shr
.
sourcefn wrapping_dist(self, other: Self) -> Self
fn wrapping_dist(self, other: Self) -> Self
Wrapping distance. Returns the distance from self
to other
, wrapping
on overflow.
See also
FixedI32::wrapping_dist
and
FixedU32::wrapping_dist
.
sourcefn unwrapped_neg(self) -> Self
fn unwrapped_neg(self) -> Self
Unwrapped negation. Returns the negated value, panicking on overflow.
See also
FixedI32::unwrapped_neg
and
FixedU32::unwrapped_neg
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_add(self, rhs: Self) -> Self
fn unwrapped_add(self, rhs: Self) -> Self
Unwrapped addition. Returns the sum, panicking on overflow.
See also
FixedI32::unwrapped_add
and
FixedU32::unwrapped_add
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_sub(self, rhs: Self) -> Self
fn unwrapped_sub(self, rhs: Self) -> Self
Unwrapped subtraction. Returns the difference, panicking on overflow.
See also
FixedI32::unwrapped_sub
and
FixedU32::unwrapped_sub
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_mul(self, rhs: Self) -> Self
fn unwrapped_mul(self, rhs: Self) -> Self
Unwrapped multiplication. Returns the product, panicking on overflow.
See also
FixedI32::unwrapped_mul
and
FixedU32::unwrapped_mul
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_rem(self, rhs: Self) -> Self
fn unwrapped_rem(self, rhs: Self) -> Self
Unwrapped remainder. Returns the quotient, panicking if the divisor is zero.
See also
FixedI32::unwrapped_rem
and
FixedU32::unwrapped_rem
.
Panics
Panics if the divisor is zero.
sourcefn unwrapped_next_multiple_of(self, other: Self) -> Self
fn unwrapped_next_multiple_of(self, other: Self) -> Self
Unwrapped next multiple of other
. Returns the next multiple, panicking
on overflow.
See also
FixedI32::unwrapped_next_multiple_of
and
FixedU32::unwrapped_next_multiple_of
.
Panics
Panics if other
is zero or on overflow.
sourcefn unwrapped_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> Self
fn unwrapped_mul_add<const MUL_FRAC: i32>( self, mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>, add: Self ) -> Self
Unwrapped multiply and add. Returns self
× mul
+ add
, panicking on overflow.
See also
FixedI32::unwrapped_mul_add
and
FixedU32::unwrapped_mul_add
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> Self
fn unwrapped_add_prod<const A_FRAC: i32, const B_FRAC: i32>( self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> ) -> Self
Adds self
to the product a
× b
, panicking on overflow.
See also
FixedI32::unwrapped_add_prod
and
FixedU32::unwrapped_add_prod
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
)
fn unwrapped_mul_acc<const A_FRAC: i32, const B_FRAC: i32>( &mut self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> )
Unwrapped multiply and accumulate. Adds (a
× b
) to self
, panicking on overflow.
See also
FixedI32::unwrapped_mul_acc
and
FixedU32::unwrapped_mul_acc
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_rem_euclid(self, rhs: Self) -> Self
fn unwrapped_rem_euclid(self, rhs: Self) -> Self
Unwrapped remainder for Euclidean division. Returns the remainder, panicking if the divisor is zero.
See also
FixedI32::unwrapped_rem_euclid
and
FixedU32::unwrapped_rem_euclid
.
Panics
Panics if the divisor is zero.
sourcefn unwrapped_mul_int(self, rhs: Self::Bits) -> Self
fn unwrapped_mul_int(self, rhs: Self::Bits) -> Self
Unwrapped multiplication by an integer. Returns the product, panicking on overflow.
See also
FixedI32::unwrapped_mul_int
and
FixedU32::unwrapped_mul_int
.
Panics
Panics if the result does not fit.
sourcefn unwrapped_div_int(self, rhs: Self::Bits) -> Self
fn unwrapped_div_int(self, rhs: Self::Bits) -> Self
Unwrapped division by an integer. Returns the quotient, panicking on overflow.
Overflow can only occur when dividing the minimum value by −1.
See also
FixedI32::unwrapped_div_int
and
FixedU32::unwrapped_div_int
.
Panics
Panics if the divisor is zero or if the result does not fit.
sourcefn unwrapped_shl(self, rhs: u32) -> Self
fn unwrapped_shl(self, rhs: u32) -> Self
Unwrapped shift left. Panics if rhs
≥ the number of bits.
See also
FixedI32::unwrapped_shl
and
FixedU32::unwrapped_shl
.
Panics
Panics if rhs
≥ the number of bits.
sourcefn unwrapped_shr(self, rhs: u32) -> Self
fn unwrapped_shr(self, rhs: u32) -> Self
Unwrapped shift right. Panics if rhs
≥ the number of bits.
See also
FixedI32::unwrapped_shr
and
FixedU32::unwrapped_shr
.
Panics
Panics if rhs
≥ the number of bits.
sourcefn unwrapped_dist(self, other: Self) -> Self
fn unwrapped_dist(self, other: Self) -> Self
Unwrapped distance. Returns the distance from self
to other
,
panicking on overflow.
Panics
Panics if the result does not fit.
See also
FixedI32::unwrapped_dist
and
FixedU32::unwrapped_dist
.
sourcefn overflowing_neg(self) -> (Self, bool)
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.
See also
FixedI32::overflowing_neg
and
FixedU32::overflowing_neg
.
sourcefn overflowing_add(self, rhs: Self) -> (Self, bool)
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.
See also
FixedI32::overflowing_add
and
FixedU32::overflowing_add
.
sourcefn overflowing_sub(self, rhs: Self) -> (Self, bool)
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.
See also
FixedI32::overflowing_sub
and
FixedU32::overflowing_sub
.
sourcefn overflowing_mul(self, rhs: Self) -> (Self, bool)
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.
See also
FixedI32::overflowing_mul
and
FixedU32::overflowing_mul
.
sourcefn overflowing_next_multiple_of(self, other: Self) -> (Self, bool)
fn overflowing_next_multiple_of(self, other: Self) -> (Self, bool)
Overflowing next multiple of other
.
Returns a tuple of the next multiple and a bool
, indicating
whether an overflow has occurred. On overflow, the wrapped value is
returned.
See also
FixedI32::overflowing_next_multiple_of
and
FixedU32::overflowing_next_multiple_of
.
Panics
Panics if other
is zero.
sourcefn overflowing_mul_add<const MUL_FRAC: i32>(
self,
mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>,
add: Self
) -> (Self, bool)
fn overflowing_mul_add<const MUL_FRAC: i32>( self, mul: <Self::Bits as FixedBits>::Fixed<MUL_FRAC>, add: Self ) -> (Self, bool)
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.
See also
FixedI32::overflowing_mul_add
and
FixedU32::overflowing_mul_add
.
sourcefn overflowing_add_prod<const A_FRAC: i32, const B_FRAC: i32>(
self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> (Self, bool)
fn overflowing_add_prod<const A_FRAC: i32, const B_FRAC: i32>( self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> ) -> (Self, bool)
Adds self
to the product a
× b
.
Returns a tuple of the result and a bool
indicating whether an
overflow has occurred. On overflow, the wrapped value is returned.
See also
FixedI32::overflowing_add_prod
and
FixedU32::overflowing_add_prod
.
sourcefn overflowing_mul_acc<const A_FRAC: i32, const B_FRAC: i32>(
&mut self,
a: <Self::Bits as FixedBits>::Fixed<A_FRAC>,
b: <Self::Bits as FixedBits>::Fixed<B_FRAC>
) -> bool
fn overflowing_mul_acc<const A_FRAC: i32, const B_FRAC: i32>( &mut self, a: <Self::Bits as FixedBits>::Fixed<A_FRAC>, b: <Self::Bits as FixedBits>::Fixed<B_FRAC> ) -> bool
Overflowing multiply and accumulate. Adds (a
× b
) to self
,
wrapping and returning true
if overflow occurs.
See also
FixedI32::overflowing_mul_acc
and
FixedU32::overflowing_mul_acc
.
sourcefn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool)
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.
See also
FixedI32::overflowing_mul_int
and
FixedU32::overflowing_mul_int
.
sourcefn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool)
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.
See also
FixedI32::overflowing_div_int
and
FixedU32::overflowing_div_int
.
Panics
Panics if the divisor is zero.
sourcefn overflowing_shl(self, rhs: u32) -> (Self, bool)
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.
See also
FixedI32::overflowing_shl
and
FixedU32::overflowing_shl
.
sourcefn overflowing_shr(self, rhs: u32) -> (Self, bool)
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.
See also
FixedI32::overflowing_shr
and
FixedU32::overflowing_shr
.
sourcefn overflowing_dist(self, other: Self) -> (Self, bool)
fn overflowing_dist(self, other: Self) -> (Self, bool)
Overflowing distance.
Returns a tuple of the distance from self
to other
and a bool
,
indicating whether an overflow has occurred. On overflow, the wrapped
value is returned.
See also
FixedI32::overflowing_dist
and
FixedU32::overflowing_dist
.
Provided Methods§
sourcefn get_signed(&self) -> Option<&Self::Signed>
fn get_signed(&self) -> Option<&Self::Signed>
Returns a reference to self
as FixedSigned
if the type is signed,
or None
if it is unsigned.
Examples
#![feature(generic_const_exprs)]
use fixed::{
traits::Fixed,
types::{I16F16, U16F16},
};
let i = I16F16::from_num(-3.5);
match i.get_signed() {
Some(signed) => assert_eq!(signed.signum(), -1),
None => unreachable!(),
}
let u = U16F16::from_num(3.5);
assert!(u.get_signed().is_none());
sourcefn get_unsigned(&self) -> Option<&Self::Unsigned>
fn get_unsigned(&self) -> Option<&Self::Unsigned>
Returns a reference to self
as FixedUnsigned
if the type is
unsigned, or None
if it is signed.
Examples
#![feature(generic_const_exprs)]
use fixed::{
traits::Fixed,
types::{I16F16, U16F16},
};
let u = U16F16::from_num(3.5);
match u.get_unsigned() {
Some(unsigned) => assert_eq!(unsigned.next_power_of_two(), 4),
None => unreachable!(),
}
let i = I16F16::from_num(3.5);
assert!(i.get_unsigned().is_none());
sourcefn get_signed_mut(&mut self) -> Option<&mut Self::Signed>
fn get_signed_mut(&mut self) -> Option<&mut Self::Signed>
Returns a mutable reference to self
as FixedSigned
if the type is
signed, or None
if it is unsigned.
Examples
#![feature(generic_const_exprs)]
use fixed::{
traits::Fixed,
types::{I16F16, U16F16},
};
let mut i = I16F16::from_num(-3.5);
match i.get_signed_mut() {
Some(signed) => *signed = signed.signum(),
None => unreachable!(),
}
assert_eq!(i, -1);
let mut u = U16F16::from_num(3.5);
assert!(u.get_signed_mut().is_none());
sourcefn get_unsigned_mut(&mut self) -> Option<&mut Self::Unsigned>
fn get_unsigned_mut(&mut self) -> Option<&mut Self::Unsigned>
Returns a mutable reference to self
as FixedUnsigned
if the type
is unsigned, or None
if it is signed.
Examples
#![feature(generic_const_exprs)]
use fixed::{
traits::Fixed,
types::{I16F16, U16F16},
};
let mut u = U16F16::from_num(3.5);
match u.get_unsigned_mut() {
Some(unsigned) => *unsigned = unsigned.next_power_of_two(),
None => unreachable!(),
}
assert_eq!(u, 4);
let mut i = I16F16::from_num(3.5);
assert!(i.get_unsigned_mut().is_none());