#[repr(C, align(4))]pub struct NegativeI32 { /* private fields */ }Expand description
A signed value that is known to be negative.
This enables some memory layout optimization.
For example, Option<NegativeI32> is the same size as i32.
Implementations§
Source§impl NegativeI32
impl NegativeI32
Sourcepub const BITS: u32 = 32u32
pub const BITS: u32 = 32u32
The size of this negative integer type in bits.
This value is equal to i32::BITS.
Sourcepub const MIN: Self
pub const MIN: Self
The smallest value that can be represented by this negative integer type, equal to i32::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: i32) -> Option<Self>
pub const fn new(value: i32) -> Option<Self>
Creates a NegativeI32 if the given value is negative.
Sourcepub const unsafe fn new_unchecked(value: i32) -> Self
pub const unsafe fn new_unchecked(value: i32) -> Self
Creates a NegativeI32 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<PositiveI32>
pub const fn checked_abs(self) -> Option<PositiveI32>
Sourcepub const fn checked_neg(self) -> Option<PositiveI32>
pub const fn checked_neg(self) -> Option<PositiveI32>
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<PositiveI32>
pub const fn checked_mul(self, rhs: Self) -> Option<PositiveI32>
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: PositiveI32) -> Option<Self>
pub const fn checked_mul_positive(self, rhs: PositiveI32) -> 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<PositiveI32>
pub const fn checked_div(self, rhs: Self) -> Option<PositiveI32>
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 PositiveI32.
Sourcepub const fn checked_div_euclid(self, rhs: Self) -> Option<PositiveI32>
pub const fn checked_div_euclid(self, rhs: Self) -> Option<PositiveI32>
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 PositiveI32.
Sourcepub const fn checked_rem_euclid(self, rhs: i32) -> Option<PositiveI32>
pub const fn checked_rem_euclid(self, rhs: i32) -> Option<PositiveI32>
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 PositiveI32.
Sourcepub const fn saturating_abs(self) -> PositiveI32
pub const fn saturating_abs(self) -> PositiveI32
Saturating absolute value.
Computes -self, returning
PositiveI32::MAX
if self == MIN.
Sourcepub const fn saturating_neg(self) -> PositiveI32
pub const fn saturating_neg(self) -> PositiveI32
Saturating negation.
Computes -self, returning
PositiveI32::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 NegativeI32::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) -> PositiveI32
pub const fn saturating_mul(self, rhs: Self) -> PositiveI32
Saturating multiplication.
Multiplies a negative integer by another negative integer, returning a positive result.
Returns PositiveI32::MAX on overflow.
Sourcepub const fn saturating_mul_positive(self, rhs: PositiveI32) -> Self
pub const fn saturating_mul_positive(self, rhs: PositiveI32) -> Self
Saturating sign-preserving multiplication.
Multiplies a negative integer by a positive integer, returning a negative result.
Returns -1 if rhs == 0.
Returns NegativeI32::MIN on overflow.
Trait Implementations§
Source§impl Binary for NegativeI32
impl Binary for NegativeI32
Source§impl BitAnd<NegativeI32> for PositiveI32
impl BitAnd<NegativeI32> for PositiveI32
Source§type Output = PositiveI32
type Output = PositiveI32
& operator.Source§impl BitAnd<PositiveI32> for NegativeI32
impl BitAnd<PositiveI32> for NegativeI32
Source§type Output = PositiveI32
type Output = PositiveI32
& operator.Source§impl BitAnd for NegativeI32
impl BitAnd for NegativeI32
Source§impl BitAndAssign<NegativeI32> for PositiveI32
impl BitAndAssign<NegativeI32> for PositiveI32
Source§fn bitand_assign(&mut self, rhs: NegativeI32)
fn bitand_assign(&mut self, rhs: NegativeI32)
&= operation. Read moreSource§impl BitAndAssign for NegativeI32
impl BitAndAssign for NegativeI32
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitOr<NegativeI32> for PositiveI32
impl BitOr<NegativeI32> for PositiveI32
Source§type Output = NegativeI32
type Output = NegativeI32
| operator.Source§impl BitOr<NegativeI32> for i32
impl BitOr<NegativeI32> for i32
Source§type Output = NegativeI32
type Output = NegativeI32
| operator.Source§impl BitOr<PositiveI32> for NegativeI32
impl BitOr<PositiveI32> for NegativeI32
Source§type Output = NegativeI32
type Output = NegativeI32
| operator.Source§impl BitOr<i32> for NegativeI32
impl BitOr<i32> for NegativeI32
Source§impl BitOr for NegativeI32
impl BitOr for NegativeI32
Source§impl BitOrAssign<PositiveI32> for NegativeI32
impl BitOrAssign<PositiveI32> for NegativeI32
Source§fn bitor_assign(&mut self, rhs: PositiveI32)
fn bitor_assign(&mut self, rhs: PositiveI32)
|= operation. Read moreSource§impl BitOrAssign<i32> for NegativeI32
impl BitOrAssign<i32> for NegativeI32
Source§fn bitor_assign(&mut self, rhs: i32)
fn bitor_assign(&mut self, rhs: i32)
|= operation. Read moreSource§impl BitOrAssign for NegativeI32
impl BitOrAssign for NegativeI32
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitXor<NegativeI32> for PositiveI32
impl BitXor<NegativeI32> for PositiveI32
Source§type Output = NegativeI32
type Output = NegativeI32
^ operator.Source§impl BitXor<PositiveI32> for NegativeI32
impl BitXor<PositiveI32> for NegativeI32
Source§type Output = NegativeI32
type Output = NegativeI32
^ operator.Source§impl BitXor for NegativeI32
impl BitXor for NegativeI32
Source§impl BitXorAssign<PositiveI32> for NegativeI32
impl BitXorAssign<PositiveI32> for NegativeI32
Source§fn bitxor_assign(&mut self, rhs: PositiveI32)
fn bitxor_assign(&mut self, rhs: PositiveI32)
^= operation. Read moreSource§impl Clone for NegativeI32
impl Clone for NegativeI32
Source§fn clone(&self) -> NegativeI32
fn clone(&self) -> NegativeI32
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more