#[repr(C, align(8))]pub struct NegativeIsize { /* private fields */ }Expand description
A signed value that is known to be negative.
This enables some memory layout optimization.
For example, Option<NegativeIsize> is the same size as isize.
Implementations§
Source§impl NegativeIsize
impl NegativeIsize
Sourcepub const BITS: u32 = 64u32
pub const BITS: u32 = 64u32
The size of this negative integer type in bits.
This value is equal to isize::BITS.
Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this negative integer type, equal to isize::MIN.
Sourcepub const MAX: Self
pub const MAX: Self
The largest value that can be represented by this negative integer type, -1.
Sourcepub const fn new(value: isize) -> Option<Self>
pub const fn new(value: isize) -> Option<Self>
Creates a NegativeIsize if the given value is negative.
Sourcepub const unsafe fn new_unchecked(value: isize) -> Self
pub const unsafe fn new_unchecked(value: isize) -> Self
Creates a NegativeIsize without checking whether the value is negative.
This results in undefined behaviour if the value is positive.
§Safety
The value must not be positive.
Sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Returns the number of zeros in the binary representation of self.
Sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Returns the number of ones in the binary representation of self.
Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation of self.
Since the value is guaranteed to be negative, this function always returns 0.
Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation of self.
On many architectures, this function can perform better than trailing_zeros() on
the underlying integer type, as special handling of zero can be avoided.
Sourcepub const fn checked_abs(self) -> Option<PositiveIsize>
pub const fn checked_abs(self) -> Option<PositiveIsize>
Sourcepub const fn checked_neg(self) -> Option<PositiveIsize>
pub const fn checked_neg(self) -> Option<PositiveIsize>
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked addition. Adds a negative integer to another negative integer.
Checks for overflow and returns None on overflow.
As a consequence, the result cannot wrap to positive integers.
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked subtraction. Subtracts a negative integer from another negative integer.
Returns None if the result would overflow into a positive integer.
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<PositiveIsize>
pub const fn checked_mul(self, rhs: Self) -> Option<PositiveIsize>
Checked multiplication.
Multiplies a negative integer by another negative integer, returning a positive result.
Returns None if the result would overflow.
Sourcepub const fn checked_mul_positive(self, rhs: PositiveIsize) -> Option<Self>
pub const fn checked_mul_positive(self, rhs: PositiveIsize) -> Option<Self>
Checked sign-preserving multiplication. Multiplies a negative integer by a positive
integer, returning a negative result.
Returns None if rhs == 0 or the result would overflow.
Sourcepub const fn checked_div(self, rhs: Self) -> Option<PositiveIsize>
pub const fn checked_div(self, rhs: Self) -> Option<PositiveIsize>
Checked division.
Divides a negative integer by another negative integer, returning the positive quotient.
Returns None if the result would overflow.
The only case where such an overflow can occur is when one divides
MIN / -1; this is equivalent to
-MIN, a positive value that is too large to represent
as a PositiveIsize.
Sourcepub const fn checked_div_euclid(self, rhs: Self) -> Option<PositiveIsize>
pub const fn checked_div_euclid(self, rhs: Self) -> Option<PositiveIsize>
Checked Euclidean division.
Calculates the Euclidean quotient
of two negative integers, returning the positive result.
Returns None if the result would overflow.
The only case where such an overflow can occur is when one divides
MIN / -1; this is equivalent to
-MIN, a positive value that is too large to represent
as a PositiveIsize.
Sourcepub const fn checked_rem_euclid(self, rhs: isize) -> Option<PositiveIsize>
pub const fn checked_rem_euclid(self, rhs: isize) -> Option<PositiveIsize>
Checked Euclidean remainder.
Calculates the Euclidean remainder
of a negative integer and any signed integer, returning the positive result.
Returns None if rhs == 0 or the result would overflow.
The only case where such an overflow can occur is when one divides
MIN / -1; this is equivalent to
-MIN, a positive value that is too large to represent
as a PositiveIsize.
Sourcepub const fn saturating_abs(self) -> PositiveIsize
pub const fn saturating_abs(self) -> PositiveIsize
Saturating absolute value.
Computes -self, returning
PositiveIsize::MAX
if self == MIN.
Sourcepub const fn saturating_neg(self) -> PositiveIsize
pub const fn saturating_neg(self) -> PositiveIsize
Saturating negation.
Computes -self, returning
PositiveIsize::MAX
if self == MIN.
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Saturating addition. Adds a negative integer to another negative integer.
Returns NegativeIsize::MIN on overflow.
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Saturating subtraction. Subtracts a negative integer from another negative integer. Returns -1 if the result would overflow into a positive integer.
Sourcepub const fn saturating_mul(self, rhs: Self) -> PositiveIsize
pub const fn saturating_mul(self, rhs: Self) -> PositiveIsize
Saturating multiplication.
Multiplies a negative integer by another negative integer, returning a positive result.
Returns PositiveIsize::MAX on overflow.
Sourcepub const fn saturating_mul_positive(self, rhs: PositiveIsize) -> Self
pub const fn saturating_mul_positive(self, rhs: PositiveIsize) -> Self
Saturating sign-preserving multiplication.
Multiplies a negative integer by a positive integer, returning a negative result.
Returns -1 if rhs == 0.
Returns NegativeIsize::MIN on overflow.
Trait Implementations§
Source§impl Binary for NegativeIsize
impl Binary for NegativeIsize
Source§impl BitAnd<NegativeIsize> for PositiveIsize
impl BitAnd<NegativeIsize> for PositiveIsize
Source§type Output = PositiveIsize
type Output = PositiveIsize
& operator.Source§impl BitAnd<PositiveIsize> for NegativeIsize
impl BitAnd<PositiveIsize> for NegativeIsize
Source§type Output = PositiveIsize
type Output = PositiveIsize
& operator.Source§impl BitAnd for NegativeIsize
impl BitAnd for NegativeIsize
Source§impl BitAndAssign<NegativeIsize> for PositiveIsize
impl BitAndAssign<NegativeIsize> for PositiveIsize
Source§fn bitand_assign(&mut self, rhs: NegativeIsize)
fn bitand_assign(&mut self, rhs: NegativeIsize)
&= operation. Read moreSource§impl BitAndAssign for NegativeIsize
impl BitAndAssign for NegativeIsize
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitOr<NegativeIsize> for PositiveIsize
impl BitOr<NegativeIsize> for PositiveIsize
Source§type Output = NegativeIsize
type Output = NegativeIsize
| operator.Source§impl BitOr<NegativeIsize> for isize
impl BitOr<NegativeIsize> for isize
Source§type Output = NegativeIsize
type Output = NegativeIsize
| operator.Source§impl BitOr<PositiveIsize> for NegativeIsize
impl BitOr<PositiveIsize> for NegativeIsize
Source§type Output = NegativeIsize
type Output = NegativeIsize
| operator.Source§impl BitOr<isize> for NegativeIsize
impl BitOr<isize> for NegativeIsize
Source§impl BitOr for NegativeIsize
impl BitOr for NegativeIsize
Source§impl BitOrAssign<PositiveIsize> for NegativeIsize
impl BitOrAssign<PositiveIsize> for NegativeIsize
Source§fn bitor_assign(&mut self, rhs: PositiveIsize)
fn bitor_assign(&mut self, rhs: PositiveIsize)
|= operation. Read moreSource§impl BitOrAssign<isize> for NegativeIsize
impl BitOrAssign<isize> for NegativeIsize
Source§fn bitor_assign(&mut self, rhs: isize)
fn bitor_assign(&mut self, rhs: isize)
|= operation. Read moreSource§impl BitOrAssign for NegativeIsize
impl BitOrAssign for NegativeIsize
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitXor<NegativeIsize> for PositiveIsize
impl BitXor<NegativeIsize> for PositiveIsize
Source§type Output = NegativeIsize
type Output = NegativeIsize
^ operator.Source§impl BitXor<PositiveIsize> for NegativeIsize
impl BitXor<PositiveIsize> for NegativeIsize
Source§type Output = NegativeIsize
type Output = NegativeIsize
^ operator.Source§impl BitXor for NegativeIsize
impl BitXor for NegativeIsize
Source§impl BitXorAssign<PositiveIsize> for NegativeIsize
impl BitXorAssign<PositiveIsize> for NegativeIsize
Source§fn bitxor_assign(&mut self, rhs: PositiveIsize)
fn bitxor_assign(&mut self, rhs: PositiveIsize)
^= operation. Read moreSource§impl Clone for NegativeIsize
impl Clone for NegativeIsize
Source§fn clone(&self) -> NegativeIsize
fn clone(&self) -> NegativeIsize
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more