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