pub trait Fixedwhere
Self: Copy + Default + Hash + Ord + Debug + Display + Binary + Octal + LowerHex + UpperHex + FromStr<Err = ParseFixedError> + FromFixed + ToFixed + Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign + Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign + Rem<Output = Self> + RemAssign + Mul<Self::Bits, Output = Self> + MulAssign<Self::Bits> + Div<Self::Bits, Output = Self> + DivAssign<Self::Bits> + Rem<Self::Bits, Output = Self> + RemAssign<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> + 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<f32> + PartialOrd<f64> + FixedOptionalFeatures + Sealed,{
type Bits;
type Bytes;
type Frac: Unsigned;
Show 118 methods
// Required methods
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_be_bytes(bytes: Self::Bytes) -> Self;
fn from_le_bytes(bytes: Self::Bytes) -> Self;
fn from_ne_bytes(bytes: Self::Bytes) -> Self;
fn to_be_bytes(self) -> Self::Bytes;
fn to_le_bytes(self) -> Self::Bytes;
fn to_ne_bytes(self) -> Self::Bytes;
fn from_num<Src: ToFixed>(src: Src) -> Self;
fn to_num<Dst: FromFixed>(self) -> Dst;
fn checked_from_num<Src: ToFixed>(src: Src) -> Option<Self>;
fn checked_to_num<Dst: FromFixed>(self) -> Option<Dst>;
fn saturating_from_num<Src: ToFixed>(src: Src) -> Self;
fn saturating_to_num<Dst: FromFixed>(self) -> Dst;
fn wrapping_from_num<Src: ToFixed>(src: Src) -> Self;
fn wrapping_to_num<Dst: FromFixed>(self) -> Dst;
fn overflowing_from_num<Src: ToFixed>(src: Src) -> (Self, bool);
fn overflowing_to_num<Dst: FromFixed>(self) -> (Dst, bool);
fn from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
fn from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
fn from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
fn saturating_from_str(src: &str) -> Result<Self, ParseFixedError>;
fn saturating_from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
fn saturating_from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
fn saturating_from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
fn wrapping_from_str(src: &str) -> Result<Self, ParseFixedError>;
fn wrapping_from_str_binary(src: &str) -> Result<Self, ParseFixedError>;
fn wrapping_from_str_octal(src: &str) -> Result<Self, ParseFixedError>;
fn wrapping_from_str_hex(src: &str) -> Result<Self, ParseFixedError>;
fn overflowing_from_str(src: &str) -> Result<(Self, bool), ParseFixedError>;
fn overflowing_from_str_binary(
src: &str,
) -> Result<(Self, bool), ParseFixedError>;
fn overflowing_from_str_octal(
src: &str,
) -> Result<(Self, bool), ParseFixedError>;
fn overflowing_from_str_hex(
src: &str,
) -> Result<(Self, bool), ParseFixedError>;
fn int(self) -> Self;
fn frac(self) -> Self;
fn round_to_zero(self) -> Self;
fn ceil(self) -> Self;
fn floor(self) -> Self;
fn round(self) -> Self;
fn round_ties_to_even(self) -> Self;
fn checked_ceil(self) -> Option<Self>;
fn checked_floor(self) -> Option<Self>;
fn checked_round(self) -> Option<Self>;
fn checked_round_ties_to_even(self) -> Option<Self>;
fn saturating_ceil(self) -> Self;
fn saturating_floor(self) -> Self;
fn saturating_round(self) -> Self;
fn saturating_round_ties_to_even(self) -> Self;
fn wrapping_ceil(self) -> Self;
fn wrapping_floor(self) -> Self;
fn wrapping_round(self) -> Self;
fn wrapping_round_ties_to_even(self) -> Self;
fn 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_zeros(self) -> u32;
fn trailing_zeros(self) -> u32;
fn rotate_left(self, n: u32) -> Self;
fn rotate_right(self, n: u32) -> Self;
fn div_euclid(self, rhs: Self) -> Self;
fn rem_euclid(self, rhs: Self) -> Self;
fn div_euclid_int(self, rhs: Self::Bits) -> Self;
fn rem_euclid_int(self, rhs: Self::Bits) -> Self;
fn checked_neg(self) -> Option<Self>;
fn checked_add(self, rhs: Self) -> Option<Self>;
fn checked_sub(self, rhs: Self) -> Option<Self>;
fn checked_mul(self, rhs: Self) -> Option<Self>;
fn checked_div(self, rhs: Self) -> Option<Self>;
fn checked_rem(self, rhs: Self) -> Option<Self>;
fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
fn checked_mul_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_div_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_rem_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_div_euclid_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_rem_euclid_int(self, rhs: Self::Bits) -> Option<Self>;
fn checked_shl(self, rhs: u32) -> Option<Self>;
fn checked_shr(self, rhs: u32) -> Option<Self>;
fn saturating_neg(self) -> Self;
fn saturating_add(self, rhs: Self) -> Self;
fn saturating_sub(self, rhs: Self) -> Self;
fn saturating_mul(self, rhs: Self) -> Self;
fn saturating_div(self, rhs: Self) -> Self;
fn saturating_div_euclid(self, rhs: Self) -> Self;
fn saturating_mul_int(self, rhs: Self::Bits) -> Self;
fn wrapping_neg(self) -> Self;
fn wrapping_add(self, rhs: Self) -> Self;
fn wrapping_sub(self, rhs: Self) -> Self;
fn wrapping_mul(self, rhs: Self) -> Self;
fn wrapping_div(self, rhs: Self) -> Self;
fn wrapping_div_euclid(self, rhs: Self) -> Self;
fn wrapping_mul_int(self, rhs: Self::Bits) -> Self;
fn wrapping_div_int(self, rhs: Self::Bits) -> Self;
fn wrapping_div_euclid_int(self, rhs: Self::Bits) -> Self;
fn wrapping_rem_euclid_int(self, rhs: Self::Bits) -> Self;
fn wrapping_shl(self, rhs: u32) -> Self;
fn wrapping_shr(self, rhs: u32) -> Self;
fn 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_div_euclid(self, rhs: Self) -> (Self, bool);
fn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_div_euclid_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_rem_euclid_int(self, rhs: Self::Bits) -> (Self, bool);
fn overflowing_shl(self, rhs: u32) -> (Self, bool);
fn overflowing_shr(self, rhs: u32) -> (Self, bool);
// Provided methods
fn wrapping_rem_int(self, rhs: Self::Bits) -> Self { ... }
fn overflowing_rem_int(self, rhs: Self::Bits) -> (Self, bool) { ... }
}
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
use substrate_fixed::{
traits::Fixed,
types::{I8F8, I16F16},
};
fn checked_add_twice<F: Fixed>(lhs: F, rhs: F) -> Option<F> {
lhs.checked_add(rhs)?.checked_add(rhs)
}
let val1 = checked_add_twice(I8F8::from_num(5), Fixed::from_num(1.75));
assert_eq!(val1, Some(Fixed::from_num(8.5)));
// can use with different fixed-point type
let val2 = checked_add_twice(I16F16::from_num(5), Fixed::from_num(1.75));
assert_eq!(val2, Some(Fixed::from_num(8.5)));
The following example fails to compile, since the compiler cannot
infer that 500 in the checked_mul_int
call is of type F::Bits
.
use substrate_fixed::traits::Fixed;
fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F> {
rhs.checked_mul_int(500)?.checked_add(lhs)
}
One way to fix this is to add a trait bound indicating that any
u16
(which can represent 500) can be converted into F::Bits
.
use substrate_fixed::{traits::Fixed, types::U12F4};
fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
where
u16: Into<F::Bits>,
{
rhs.checked_mul_int(500.into())?.checked_add(lhs)
}
let val = checked_add_times_500(U12F4::from_num(0.25), Fixed::from_num(1.5));
assert_eq!(val, Some(Fixed::from_num(750.25)));
While this works in most cases, u16
cannot be converted to
i16
, even if the value 500 does fit in i16
, so that the
following example would fail to compile.
use substrate_fixed::{traits::Fixed, types::I12F4};
fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
where
u16: Into<F::Bits>,
{
rhs.checked_mul_int(500.into())?.checked_add(lhs)
}
// I12F4::Bits is i16, and u16 does not implement Into<i16>
let val = checked_add_times_500(I12F4::from_num(0.25), Fixed::from_num(1.5));
We can use TryFrom
to fix this, as we know that
F::Bits::try_from(500_u16)
will work for both u16
and
i16
. (The function will always return None
when F::Bits
is u8
or i8
.)
use substrate_fixed::{traits::Fixed, types::I12F4};
use core::convert::TryInto;
fn checked_add_times_500<F: Fixed>(lhs: F, rhs: F) -> Option<F>
where
u16: TryInto<F::Bits>,
{
rhs.checked_mul_int(500.try_into().ok()?)?.checked_add(lhs)
}
let val = checked_add_times_500(I12F4::from_num(0.25), Fixed::from_num(1.5));
assert_eq!(val, Some(Fixed::from_num(750.25)));
Required Associated Types§
Required Methods§
Sourcefn frac_nbits() -> u32
fn frac_nbits() -> u32
Returns the number of fractional bits.
Sourcefn from_bits(bits: Self::Bits) -> Self
fn from_bits(bits: Self::Bits) -> Self
Creates a fixed-point number that has a bitwise representation identical to the given integer.
Sourcefn to_bits(self) -> Self::Bits
fn to_bits(self) -> Self::Bits
Creates an integer that has a bitwise representation identical to the given fixed-point number.
Sourcefn from_be_bytes(bytes: Self::Bytes) -> Self
fn from_be_bytes(bytes: Self::Bytes) -> Self
Creates a fixed-point number from its representation as a byte array in big endian.
Sourcefn from_le_bytes(bytes: Self::Bytes) -> Self
fn from_le_bytes(bytes: Self::Bytes) -> Self
Creates a fixed-point number from its representation as a byte array in little endian.
Sourcefn from_ne_bytes(bytes: Self::Bytes) -> Self
fn from_ne_bytes(bytes: Self::Bytes) -> Self
Creates a fixed-point number from its representation as a byte array in native endian.
Sourcefn to_be_bytes(self) -> Self::Bytes
fn to_be_bytes(self) -> Self::Bytes
Returns the memory representation of this fixed-point number as a byte array in big-endian byte order.
Sourcefn to_le_bytes(self) -> Self::Bytes
fn to_le_bytes(self) -> Self::Bytes
Returns the memory representation of this fixed-point number as a byte array in little-endian byte order.
Sourcefn to_ne_bytes(self) -> Self::Bytes
fn to_ne_bytes(self) -> Self::Bytes
Returns the memory representation of this fixed-point number as a byte array in native byte order.
Sourcefn from_num<Src: ToFixed>(src: Src) -> Self
fn from_num<Src: ToFixed>(src: Src) -> Self
Creates a fixed-point number from another number.
Returns the same value as src.to_fixed()
.
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()
.
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)
.
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()
.
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)
.
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()
.
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 Src::wrapping_from_fixed(self)
.
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()
.
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)
.
Sourcefn from_str_binary(src: &str) -> Result<Self, ParseFixedError>
fn from_str_binary(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing binary digits to return a fixed-point number.
Rounding is to the nearest, with ties rounded to even.
Sourcefn from_str_octal(src: &str) -> Result<Self, ParseFixedError>
fn from_str_octal(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing octal digits to return a fixed-point number.
Rounding is to the nearest, with ties rounded to even.
Sourcefn from_str_hex(src: &str) -> Result<Self, ParseFixedError>
fn from_str_hex(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing hexadecimal digits to return a fixed-point number.
Rounding is to the nearest, with ties rounded to even.
Sourcefn saturating_from_str(src: &str) -> Result<Self, ParseFixedError>
fn saturating_from_str(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing decimal digits to return a fixed-point number, saturating on overflow.
Rounding is to the nearest, with ties rounded to even.
Sourcefn saturating_from_str_binary(src: &str) -> Result<Self, ParseFixedError>
fn saturating_from_str_binary(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing binary digits to return a fixed-point number, saturating on overflow.
Rounding is to the nearest, with ties rounded to even.
Sourcefn saturating_from_str_octal(src: &str) -> Result<Self, ParseFixedError>
fn saturating_from_str_octal(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing octal digits to return a fixed-point number, saturating on overflow.
Rounding is to the nearest, with ties rounded to even.
Sourcefn saturating_from_str_hex(src: &str) -> Result<Self, ParseFixedError>
fn saturating_from_str_hex(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing hexadecimal digits to return a fixed-point number, saturating on overflow.
Rounding is to the nearest, with ties rounded to even.
Sourcefn wrapping_from_str(src: &str) -> Result<Self, ParseFixedError>
fn wrapping_from_str(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing decimal digits to return a fixed-point number, wrapping on overflow.
Rounding is to the nearest, with ties rounded to even.
Sourcefn wrapping_from_str_binary(src: &str) -> Result<Self, ParseFixedError>
fn wrapping_from_str_binary(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing binary digits to return a fixed-point number, wrapping on overflow.
Rounding is to the nearest, with ties rounded to even.
Sourcefn wrapping_from_str_octal(src: &str) -> Result<Self, ParseFixedError>
fn wrapping_from_str_octal(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing octal digits to return a fixed-point number, wrapping on overflow.
Rounding is to the nearest, with ties rounded to even.
Sourcefn wrapping_from_str_hex(src: &str) -> Result<Self, ParseFixedError>
fn wrapping_from_str_hex(src: &str) -> Result<Self, ParseFixedError>
Parses a string slice containing hexadecimal digits to return a fixed-point number, wrapping on overflow.
Rounding is to the nearest, with ties rounded to even.
Sourcefn overflowing_from_str(src: &str) -> Result<(Self, bool), ParseFixedError>
fn overflowing_from_str(src: &str) -> Result<(Self, bool), ParseFixedError>
Sourcefn overflowing_from_str_binary(
src: &str,
) -> Result<(Self, bool), ParseFixedError>
fn overflowing_from_str_binary( src: &str, ) -> Result<(Self, bool), ParseFixedError>
Sourcefn overflowing_from_str_octal(
src: &str,
) -> Result<(Self, bool), ParseFixedError>
fn overflowing_from_str_octal( src: &str, ) -> Result<(Self, bool), ParseFixedError>
Sourcefn overflowing_from_str_hex(src: &str) -> Result<(Self, bool), ParseFixedError>
fn overflowing_from_str_hex(src: &str) -> Result<(Self, bool), ParseFixedError>
Sourcefn round_to_zero(self) -> Self
fn round_to_zero(self) -> Self
Rounds to the next integer towards 0.
Sourcefn round_ties_to_even(self) -> Self
fn round_ties_to_even(self) -> Self
Rounds to the nearest integer, with ties rounded 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.
Sourcefn checked_floor(self) -> Option<Self>
fn checked_floor(self) -> Option<Self>
Checked floor. Rounds to the next integer towards −∞, returning
None
on overflow.
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.
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.
Sourcefn saturating_ceil(self) -> Self
fn saturating_ceil(self) -> Self
Saturating ceil. Rounds to the next integer towards +∞, saturating on overflow.
Sourcefn saturating_floor(self) -> Self
fn saturating_floor(self) -> Self
Saturating floor. Rounds to the next integer towards −∞, saturating on overflow.
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.
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.
Sourcefn wrapping_ceil(self) -> Self
fn wrapping_ceil(self) -> Self
Wrapping ceil. Rounds to the next integer towards +∞, wrapping on overflow.
Sourcefn wrapping_floor(self) -> Self
fn wrapping_floor(self) -> Self
Wrapping floor. Rounds to the next integer towards −∞, wrapping on overflow.
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.
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.
Sourcefn overflowing_ceil(self) -> (Self, bool)
fn overflowing_ceil(self) -> (Self, bool)
Sourcefn overflowing_floor(self) -> (Self, bool)
fn overflowing_floor(self) -> (Self, bool)
Sourcefn overflowing_round(self) -> (Self, bool)
fn overflowing_round(self) -> (Self, bool)
Sourcefn overflowing_round_ties_to_even(self) -> (Self, bool)
fn overflowing_round_ties_to_even(self) -> (Self, bool)
Sourcefn count_ones(self) -> u32
fn count_ones(self) -> u32
Returns the number of ones in the binary representation.
Sourcefn count_zeros(self) -> u32
fn count_zeros(self) -> u32
Returns the number of zeros in the binary representation.
Sourcefn leading_zeros(self) -> u32
fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation.
Sourcefn trailing_zeros(self) -> u32
fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation.
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.
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.
Sourcefn div_euclid(self, rhs: Self) -> Self
fn div_euclid(self, rhs: Self) -> Self
Euclidean division by an integer.
§Panics
Panics if the divisor is zero or if the division results in overflow.
Sourcefn rem_euclid(self, rhs: Self) -> Self
fn rem_euclid(self, rhs: Self) -> Self
Sourcefn div_euclid_int(self, rhs: Self::Bits) -> Self
fn div_euclid_int(self, rhs: Self::Bits) -> Self
Euclidean division by an integer.
§Panics
Panics if the divisor is zero or if the division results in overflow.
Sourcefn rem_euclid_int(self, rhs: Self::Bits) -> Self
fn rem_euclid_int(self, rhs: Self::Bits) -> Self
Remainder for Euclidean division by an integer.
§Panics
Panics if the divisor is zero or if the division results in overflow.
Sourcefn checked_neg(self) -> Option<Self>
fn checked_neg(self) -> Option<Self>
Checked negation. Returns the negated value, or None
on overflow.
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.
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.
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.
Sourcefn checked_div(self, rhs: Self) -> Option<Self>
fn checked_div(self, rhs: Self) -> Option<Self>
Checked division. Returns the quotient, or None
if the
divisor is zero or on overflow.
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.
Sourcefn checked_div_euclid(self, rhs: Self) -> Option<Self>
fn checked_div_euclid(self, rhs: Self) -> Option<Self>
Checked remainder for Euclidean division. Returns the
remainder, or None
if the divisor is zero or the division
results in overflow.
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.
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.
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.
Sourcefn checked_rem_int(self, rhs: Self::Bits) -> Option<Self>
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.
Sourcefn checked_div_euclid_int(self, rhs: Self::Bits) -> Option<Self>
fn checked_div_euclid_int(self, rhs: Self::Bits) -> Option<Self>
Checked Euclidean division by an integer. Returns the
quotient, or None
if the divisor is zero or if the
division results in overflow.
Sourcefn checked_rem_euclid_int(self, rhs: Self::Bits) -> Option<Self>
fn checked_rem_euclid_int(self, rhs: Self::Bits) -> Option<Self>
Checked remainder for Euclidean division by an integer.
Returns the remainder, or None
if the divisor is zero or
if the remainder results in overflow.
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.
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.
Sourcefn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
Saturated negation. Returns the negated value, saturating on overflow.
Sourcefn saturating_add(self, rhs: Self) -> Self
fn saturating_add(self, rhs: Self) -> Self
Saturating addition. Returns the sum, saturating on overflow.
Sourcefn saturating_sub(self, rhs: Self) -> Self
fn saturating_sub(self, rhs: Self) -> Self
Saturating subtraction. Returns the difference, saturating on overflow.
Sourcefn saturating_mul(self, rhs: Self) -> Self
fn saturating_mul(self, rhs: Self) -> Self
Saturating multiplication. Returns the product, saturating on overflow.
Sourcefn saturating_div(self, rhs: Self) -> Self
fn saturating_div(self, rhs: Self) -> Self
Saturating division. Returns the quotient, saturating on overflow.
§Panics
Panics if the divisor is zero.
Sourcefn saturating_div_euclid(self, rhs: Self) -> Self
fn saturating_div_euclid(self, rhs: Self) -> Self
Saturating Euclidean division. Returns the quotient, saturating on overflow.
§Panics
Panics if the divisor is zero.
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.
Sourcefn wrapping_neg(self) -> Self
fn wrapping_neg(self) -> Self
Wrapping negation. Returns the negated value, wrapping on overflow.
Sourcefn wrapping_add(self, rhs: Self) -> Self
fn wrapping_add(self, rhs: Self) -> Self
Wrapping addition. Returns the sum, wrapping on overflow.
Sourcefn wrapping_sub(self, rhs: Self) -> Self
fn wrapping_sub(self, rhs: Self) -> Self
Wrapping subtraction. Returns the difference, wrapping on overflow.
Sourcefn wrapping_mul(self, rhs: Self) -> Self
fn wrapping_mul(self, rhs: Self) -> Self
Wrapping multiplication. Returns the product, wrapping on overflow.
Sourcefn wrapping_div(self, rhs: Self) -> Self
fn wrapping_div(self, rhs: Self) -> Self
Wrapping division. Returns the quotient, wrapping on overflow.
§Panics
Panics if the divisor is zero.
Sourcefn wrapping_div_euclid(self, rhs: Self) -> Self
fn wrapping_div_euclid(self, rhs: Self) -> Self
Wrapping Euclidean division. Returns the quotient, wrapping on overflow.
§Panics
Panics if the divisor is zero.
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.
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.
§Panics
Panics if the divisor is zero.
Sourcefn wrapping_div_euclid_int(self, rhs: Self::Bits) -> Self
fn wrapping_div_euclid_int(self, rhs: Self::Bits) -> Self
Wrapping Euclidean division by an integer. Returns the quotient, wrapping on overflow.
Overflow can only occur when dividing the minimum value by −1.
§Panics
Panics if the divisor is zero.
Sourcefn wrapping_rem_euclid_int(self, rhs: Self::Bits) -> Self
fn wrapping_rem_euclid_int(self, rhs: Self::Bits) -> Self
Wrapping remainder for Euclidean division by an integer. Returns the remainder, wrapping on overflow.
§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.
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.
Sourcefn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
Sourcefn overflowing_add(self, rhs: Self) -> (Self, bool)
fn overflowing_add(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_sub(self, rhs: Self) -> (Self, bool)
fn overflowing_sub(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_mul(self, rhs: Self) -> (Self, bool)
fn overflowing_mul(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_div(self, rhs: Self) -> (Self, bool)
fn overflowing_div(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)
fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)
Sourcefn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool)
fn overflowing_mul_int(self, rhs: Self::Bits) -> (Self, bool)
Sourcefn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool)
fn overflowing_div_int(self, rhs: Self::Bits) -> (Self, bool)
Sourcefn overflowing_div_euclid_int(self, rhs: Self::Bits) -> (Self, bool)
fn overflowing_div_euclid_int(self, rhs: Self::Bits) -> (Self, bool)
Sourcefn overflowing_rem_euclid_int(self, rhs: Self::Bits) -> (Self, bool)
fn overflowing_rem_euclid_int(self, rhs: Self::Bits) -> (Self, bool)
Sourcefn overflowing_shl(self, rhs: u32) -> (Self, bool)
fn overflowing_shl(self, rhs: u32) -> (Self, bool)
Provided Methods§
Sourcefn wrapping_rem_int(self, rhs: Self::Bits) -> Self
👎Deprecated since 0.5.3: cannot overflow, use %
or Rem::rem
instead
fn wrapping_rem_int(self, rhs: Self::Bits) -> Self
%
or Rem::rem
insteadSourcefn overflowing_rem_int(self, rhs: Self::Bits) -> (Self, bool)
👎Deprecated since 0.5.3: cannot overflow, use %
or Rem::rem
instead
fn overflowing_rem_int(self, rhs: Self::Bits) -> (Self, bool)
%
or Rem::rem
insteadDyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.