[−][src]Trait funty::IsInteger
Declare that a type is a fixed-point integer.
This unifies all of the signed and unsigned integral types.
Associated Constants
pub const ZERO: Self
[src]
The type’s zero value.
pub const MIN: Self
[src]
The type’s minimum value. This is zero for unsigned integers.
pub const MAX: Self
[src]
The type’s maximum value.
Required methods
pub fn min_value() -> Self
[src]
Returns the smallest value that can be represented by this integer type.
pub fn max_value() -> Self
[src]
Returns the largest value that can be represented by this integer type.
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>
[src]
Converts a string slice in a given base to an integer.
The string is expected to be an optional +
or -
sign followed by
digits. Leading and trailing whitespace represent an error. Digits are a
subset of these characters, depending on radix
:
0-9
a-z
A-Z
Panics
This function panics if radix
is not in the range from 2 to 36.
pub fn count_ones(self) -> u32
[src]
Returns the number of ones in the binary representation of self
.
pub fn count_zeros(self) -> u32
[src]
Returns the number of zeros in the binary representation of self
.
pub fn leading_zeros(self) -> u32
[src]
Returns the number of leading zeros in the binary representation of
self
.
pub fn trailing_zeros(self) -> u32
[src]
Returns the number of trailing zeros in the binary representation of
self
.
pub fn leading_ones(self) -> u32
[src]
Returns the number of leading ones in the binary representation of
self
.
pub fn trailing_ones(self) -> u32
[src]
Returns the number of trailing ones in the binary representation of
self
.
pub fn rotate_left(self, n: u32) -> Self
[src]
Shifts the bits to the left by a specified amount, n
, wrapping the
truncated bits to the end of the resulting integer.
Please note this isn’t the same operation as the <<
shifting operator!
pub fn rotate_right(self, n: u32) -> Self
[src]
Shifts the bits to the right by a specified amount, n
, wrapping the
truncated bits to the beginning of the resulting integer.
Please note this isn’t the same operation as the >>
shifting operator!
pub fn swap_bytes(self) -> Self
[src]
Reverses the byte order of the integer.
pub fn reverse_bits(self) -> Self
[src]
Reverses the bit pattern of the integer.
pub fn from_be(self) -> Self
[src]
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
pub fn from_le(self) -> Self
[src]
Converts an integer frm little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
pub fn to_be(self) -> Self
[src]
Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
pub fn to_le(self) -> Self
[src]
Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
pub fn checked_add(self, rhs: Self) -> Option<Self>
[src]
Checked integer addition. Computes self + rhs
, returning None
if
overflow occurred.
pub fn checked_sub(self, rhs: Self) -> Option<Self>
[src]
Checked integer subtraction. Computes self - rhs
, returning None
if
overflow occurred.
pub fn checked_mul(self, rhs: Self) -> Option<Self>
[src]
Checked integer multiplication. Computes self * rhs
, returning None
if overflow occurred.
pub fn checked_div(self, rhs: Self) -> Option<Self>
[src]
Checked integer division. Computes self / rhs
, returning None
if
rhs == 0
or the division results in overflow.
pub fn checked_div_euclid(self, rhs: Self) -> Option<Self>
[src]
Checked Euclidean division. Computes self.div_euclid(rhs)
, returning
None
if rhs == 0
or the division results in overflow.
pub fn checked_rem(self, rhs: Self) -> Option<Self>
[src]
Checked integer remainder. Computes self % rhs
, returning None
if
rhs == 0
or the division results in overflow.
pub fn checked_rem_euclid(self, rhs: Self) -> Option<Self>
[src]
Checked Euclidean remainder. Computes self.rem_euclid(rhs)
, returning
None
if rhs == 0
or the division results in overflow.
pub fn checked_neg(self) -> Option<Self>
[src]
Checked negation. Computes -self
, returning None
if self == MIN
.
Note that negating any positive integer will overflow.
pub fn checked_shl(self, rhs: u32) -> Option<Self>
[src]
Checked shift left. Computes self << rhs
, returning None
if rhs
is
larger than or equal to the number of bits in self
.
pub fn checked_shr(self, rhs: u32) -> Option<Self>
[src]
Checked shift right. Computes self >> rhs
, returning None
if rhs
is larger than or equal to the number of bits in self
.
pub fn checked_pow(self, rhs: u32) -> Option<Self>
[src]
Checked exponentiation. Computes self.pow(exp)
, returning None
if
overflow occurred.
pub fn saturating_add(self, rhs: Self) -> Self
[src]
Saturating integer addition. Computes self + rhs
, saturating at the
numeric bounds instead of overflowing.
pub fn saturating_sub(self, rhs: Self) -> Self
[src]
Saturating integer subtraction. Computes self - rhs
, saturating at the
numeric bounds instead of overflowing.
pub fn saturating_mul(self, rhs: Self) -> Self
[src]
Saturating integer multiplication. Computes self * rhs
, saturating at
the numeric bounds instead of overflowing.
pub fn saturating_pow(self, rhs: u32) -> Self
[src]
Saturating integer exponentiation. Computes self.pow(exp)
, saturating
at the numeric bounds instead of overflowing.
pub fn wrapping_add(self, rhs: Self) -> Self
[src]
Wrapping (modular) addition. Computes self + rhs
, wrapping around at
the boundary of the type.
pub fn wrapping_sub(self, rhs: Self) -> Self
[src]
Wrapping (modular) subtraction. Computes self - rhs
, wrapping around
at the boundary of the type.
pub fn wrapping_mul(self, rhs: Self) -> Self
[src]
Wrapping (modular) multiplication. Computes self * rhs
, wrapping
around at the boundary of the type.
pub fn wrapping_div(self, rhs: Self) -> Self
[src]
Wrapping (modular) division. Computes self / rhs
, wrapping around at
the boundary of the type.
Signed Integers
The only case where such wrapping can occur is when one divides
MIN / -1
on a signed type (where MIN
is the negative minimal value
for the type); this is equivalent to -MIN
, a positive value that is
too large to represent in the type. In such a case, this function
returns MIN
itself.
Unsigned Integers
Wrapping (modular) division. Computes self / rhs
. Wrapped division on
unsigned types is just normal division. There’s no way wrapping could
ever happen. This function exists, so that all operations are accounted
for in the wrapping operations.
Panics
This function will panic if rhs
is 0.
pub fn wrapping_div_euclid(self, rhs: Self) -> Self
[src]
Wrapping Eulidean division. Computes self.div_euclid(rhs)
, wrapping
around at the boundary of the type.
Signed Types
Wrapping will only occur in MIN / -1
on a signed type (where MIN
is
the negative minimal value for the type). This is equivalent to -MIN
,
a positive value that is too large to represent in the type. In this
case, this method returns MIN
itself.
Unsigned Types
Wrapped division on unsigned types is just normal division. There’s no
way wrapping could ever happen. This function exists, so that all
operations are accounted for in the wrapping operations. Since, for the
positive integers, all common definitions of division are equal, this is
exactly equal to self.wrapping_div(rhs)
.
Panics
This function will panic if rhs
is 0.
pub fn wrapping_rem(self, rhs: Self) -> Self
[src]
Wrapping (modular) remainder. Computes self % rhs
, wrapping around at
the boundary of the type.
Signed Integers
Such wrap-around never actually occurs mathematically; implementation
artifacts make x % y
invalid for MIN / -1
on a signed type (where
MIN
is the negative minimal value). In such a case, this function
returns 0
.
Unsigned Integers
Wrapped remainder calculation on unsigned types is just the regular remainder calculation. There’s no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations.
Panics
This function will panic if rhs
is 0.
pub fn wrapping_rem_euclid(self, rhs: Self) -> Self
[src]
Wrapping Euclidean remainder. Computes self.rem_euclid(rhs)
, wrapping
around at the boundary of the type.
Signed Integers
Wrapping will only occur in MIN % -1
on a signed type (where MIN
is
the negative minimal value for the type). In this case, this method
returns 0.
Unsigned Integers
Wrapped modulo calculation on unsigned types is just the regular
remainder calculation. There’s no way wrapping could ever happen. This
function exists, so that all operations are accounted for in the
wrapping operations. Since, for the positive integers, all common
definitions of division are equal, this is exactly equal to
self.wrapping_rem(rhs)
.
Panics
This function will panic if rhs
is 0.
pub fn wrapping_neg(self) -> Self
[src]
Wrapping (modular) negation. Computes -self
, wrapping around at the
boundary of the type.
Signed Integers
The only case where such wrapping can occur is when one negates MIN
on a signed type (where MIN
is the negative minimal value for the
type); this is a positive value that is too large to represent in the
type. In such a case, this function returns MIN
itself.
Unsigned Integers
Since unsigned types do not have negative equivalents all applications
of this function will wrap (except for -0
). For values smaller than
the corresponding signed type’s maximum the result is the same as
casting the corresponding signed value. Any larger values are equivalent
to MAX + 1 - (val - MAX - 1)
where MAX
is the corresponding signed
type’s maximum.
pub fn wrapping_shl(self, rhs: u32) -> Self
[src]
Panic-free bitwise shift-left; yields self << mask(rhs)
, where mask
removes any high-order bits of rhs
that would cause the shift to
exceed the bitwidth of the type.
Note that this is not the same as a rotate-left; the RHS of a wrapping
shift-left is restricted to the range of the type, rather than the bits
shifted out of the LHS being returned to the other end. The primitive
integer types all implement a rotate_left
function, which may be what
you want instead.
pub fn wrapping_shr(self, rhs: u32) -> Self
[src]
Panic-free bitwise shift-right; yields self >> mask(rhs)
, where mask
removes any high-order bits of rhs
that would cause the shift to
exceed the bitwidth of the type.
Note that this is not the same as a rotate-right; the RHS of a wrapping
shift-right is restricted to the range of the type, rather than the bits
shifted out of the LHS being returned to the other end. The primitive
integer types all implement a rotate_right
function, which may be what
you want instead.
pub fn wrapping_pow(self, rhs: u32) -> Self
[src]
Wrapping (modular) exponentiation. Computes self.pow(exp)
, wrapping
around at the boundary of the type.
pub fn overflowing_add(self, rhs: Self) -> (Self, bool)
[src]
Calculates self + rhs
Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
pub fn overflowing_sub(self, rhs: Self) -> (Self, bool)
[src]
Calculates self - rhs
Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
pub fn overflowing_mul(self, rhs: Self) -> (Self, bool)
[src]
Calculates the multiplication of self
and rhs
.
Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
pub fn overflowing_div(self, rhs: Self) -> (Self, bool)
[src]
Calculates the divisor when self
is divided by rhs
.
Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then self is returned.
Panics
This function will panic if rhs
is 0.
pub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool)
[src]
Calculates the quotient of Euclidean division self.div_euclid(rhs)
.
Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then self is returned.
Panics
This function will panic if rhs
is 0.
pub fn overflowing_rem(self, rhs: Self) -> (Self, bool)
[src]
Calculates the remainder when self
is divided by rhs
.
Returns a tuple of the remainder after dividing along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then 0 is returned.
Panics
This function will panic if rhs
is 0.
pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool)
[src]
Overflowing Euclidean remainder. Calculates self.rem_euclid(rhs)
.
Returns a tuple of the remainder after dividing along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would occur then 0 is returned.
Panics
This function will panic if rhs is 0.
pub fn overflowing_neg(self) -> (Self, bool)
[src]
Negates self, overflowing if this is equal to the minimum value.
Returns a tuple of the negated version of self along with a boolean
indicating whether an overflow happened. If self
is the minimum value
(e.g., i32::MIN
for values of type i32
), then the minimum value will
be returned again and true
will be returned for an overflow happening.
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool)
[src]
Shifts self left by rhs
bits.
Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.
pub fn overflowing_shr(self, rhs: u32) -> (Self, bool)
[src]
Shifts self right by rhs
bits.
Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.
pub fn overflowing_pow(self, rhs: u32) -> (Self, bool)
[src]
Raises self to the power of exp
, using exponentiation by squaring.
Returns a tuple of the exponentiation along with a bool indicating whether an overflow happened.
pub fn pow(self, rhs: u32) -> Self
[src]
Raises self to the power of exp
, using exponentiation by squaring.
pub fn div_euclid(self, rhs: Self) -> Self
[src]
Calculates the quotient of Euclidean division of self by rhs.
This computes the integer n
such that
self = n * rhs + self.rem_euclid(rhs)
, with
0 <= self.rem_euclid(rhs) < rhs
.
In other words, the result is self / rhs
rounded to the integer n
such that self >= n * rhs
. If self > 0
, this is equal to round
towards zero (the default in Rust); if self < 0
, this is equal to
round towards +/- infinity.
Panics
This function will panic if rhs
is 0 or the division results in
overflow.
pub fn rem_euclid(self, rhs: Self) -> Self
[src]
Calculates the least nonnegative remainder of self (mod rhs)
.
This is done as if by the Euclidean division algorithm -- given
r = self.rem_euclid(rhs)
, self = rhs * self.div_euclid(rhs) + r
, and
0 <= r < abs(rhs)
.
Panics
This function will panic if rhs
is 0 or the division results in
overflow.