pub struct Int<T: SignedInteger + BuiltinInteger, const BITS: usize> { /* private fields */ }
Implementations§
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Int<T, BITS>
pub const BITS: usize = BITS
Sourcepub const fn value(self) -> T
pub const fn value(self) -> T
Returns the type as a fundamental data type.
Note that if negative, the returned value may span more bits than BITS
,
as it preserves the numeric value instead of the bitwise value:
let value: i8 = i3::new(-1).value();
assert_eq!(value, -1);
assert_eq!(value.count_ones(), 8);
If you need a value within the specified bit range, use Self::to_bits
.
Sourcepub const unsafe fn new_unchecked(value: T) -> Self
pub const unsafe fn new_unchecked(value: T) -> Self
Source§impl<const BITS: usize> Int<i8, BITS>
impl<const BITS: usize> Int<i8, BITS>
pub const MASK: i8
Sourcepub const fn new(value: i8) -> Self
pub const fn new(value: i8) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i8(value: i8) -> Self
pub const fn from_i8(value: i8) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i16(value: i16) -> Self
pub const fn from_i16(value: i16) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i32(value: i32) -> Self
pub const fn from_i32(value: i32) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i64(value: i64) -> Self
pub const fn from_i64(value: i64) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i128(value: i128) -> Self
pub const fn from_i128(value: i128) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn try_new(value: i8) -> Result<Self, TryNewError>
pub const fn try_new(value: i8) -> Result<Self, TryNewError>
Creates an instance or an error if the given value is outside of the valid range
Sourcepub const fn to_bits(self) -> u8
pub const fn to_bits(self) -> u8
Returns the bitwise representation of the value.
As the bit width is limited to BITS
the numeric value may differ from value
.
let value = i3::new(-1);
assert_eq!(value.to_bits(), 0b111); // 7
assert_eq!(value.value(), -1);
To convert from the bitwise representation back to an instance, use from_bits
.
Sourcepub const fn from_bits(value: u8) -> Self
pub const fn from_bits(value: u8) -> Self
Convert the bitwise representation from to_bits
to an instance.
let value = i3::from_bits(0b111);
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use new
.
§Panics
Panics if the given value exceeds the bit width specified by BITS
.
Sourcepub const fn try_from_bits(value: u8) -> Result<Self, TryNewError>
pub const fn try_from_bits(value: u8) -> Result<Self, TryNewError>
Tries to convert the bitwise representation from to_bits
to an instance.
i3::try_from_bits(0b1111).expect_err("value is > 3 bits");
let value = i3::try_from_bits(0b111).expect("value is <= 3 bits");
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use try_new
.
§Errors
Returns an error if the given value exceeds the bit width specified by BITS
.
Sourcepub const unsafe fn from_bits_unchecked(value: u8) -> Self
pub const unsafe fn from_bits_unchecked(value: u8) -> Self
Converts the bitwise representation from to_bits
to an instance,
without checking the bounds.
§Safety
The given value must not exceed the bit width specified by Self::BITS
.
Sourcepub const fn extract_i8(value: i8, start_bit: usize) -> Self
pub const fn extract_i8(value: i8, start_bit: usize) -> Self
Sourcepub const fn extract_u8(value: u8, start_bit: usize) -> Self
pub const fn extract_u8(value: u8, start_bit: usize) -> Self
Sourcepub const fn extract_i16(value: i16, start_bit: usize) -> Self
pub const fn extract_i16(value: i16, start_bit: usize) -> Self
Sourcepub const fn extract_u16(value: u16, start_bit: usize) -> Self
pub const fn extract_u16(value: u16, start_bit: usize) -> Self
Sourcepub const fn extract_i32(value: i32, start_bit: usize) -> Self
pub const fn extract_i32(value: i32, start_bit: usize) -> Self
Sourcepub const fn extract_u32(value: u32, start_bit: usize) -> Self
pub const fn extract_u32(value: u32, start_bit: usize) -> Self
Sourcepub const fn extract_i64(value: i64, start_bit: usize) -> Self
pub const fn extract_i64(value: i64, start_bit: usize) -> Self
Sourcepub const fn extract_u64(value: u64, start_bit: usize) -> Self
pub const fn extract_u64(value: u64, start_bit: usize) -> Self
Sourcepub const fn extract_i128(value: i128, start_bit: usize) -> Self
pub const fn extract_i128(value: i128, start_bit: usize) -> Self
Sourcepub const fn extract_u128(value: u128, start_bit: usize) -> Self
pub const fn extract_u128(value: u128, start_bit: usize) -> Self
Sourcepub const fn widen<const BITS_RESULT: usize>(self) -> Int<i8, BITS_RESULT>
pub const fn widen<const BITS_RESULT: usize>(self) -> Int<i8, BITS_RESULT>
Returns an Int
with a wider bit depth but with the same base data type
Sourcepub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
Wrapping (modular) addition. Computes self + rhs
, wrapping around at the
boundary of the type.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_add(i14::new(27)), i14::new(127));
assert_eq!(i14::MAX.wrapping_add(i14::new(2)), i14::MIN + i14::new(1));
Sourcepub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
Wrapping (modular) subtraction. Computes self - rhs
, wrapping around at the
boundary of the type.
§Examples
Basic usage:
assert_eq!(i14::new(0).wrapping_sub(i14::new(127)), i14::new(-127));
assert_eq!(i14::new(-2).wrapping_sub(i14::MAX), i14::MAX);
Sourcepub const fn wrapping_mul(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Wrapping (modular) multiplication. Computes self * rhs
, wrapping around at the
boundary of the type.
§Examples
Basic usage:
assert_eq!(i14::new(10).wrapping_mul(i14::new(12)), i14::new(120));
assert_eq!(i14::new(12).wrapping_mul(i14::new(1024)), i14::new(-4096));
Sourcepub const fn wrapping_div(self, rhs: Self) -> Self
pub const fn wrapping_div(self, rhs: Self) -> Self
Wrapping (modular) division. Computes self / rhs
, wrapping around at the
boundary of the type.
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.
§Panics
This function will panic if rhs
is zero.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_div(i14::new(10)), i14::new(10));
assert_eq!(i14::MIN.wrapping_div(i14::new(-1)), i14::MIN);
Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self
, wrapping around at the boundary of the type.
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.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_neg(), i14::new(-100));
assert_eq!(i14::new(-100).wrapping_neg(), i14::new(100));
assert_eq!(i14::MIN.wrapping_neg(), i14::MIN);
Sourcepub const fn wrapping_shl(self, rhs: u32) -> Self
pub const fn wrapping_shl(self, rhs: u32) -> Self
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.
A rotate_left
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-1).wrapping_shl(7), i14::new(-128));
assert_eq!(i14::new(-1).wrapping_shl(128), i14::new(-4));
Sourcepub const fn wrapping_shr(self, rhs: u32) -> Self
pub const fn wrapping_shr(self, rhs: u32) -> Self
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.
A rotate_right
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-128).wrapping_shr(7), i14::new(-1));
assert_eq!(i14::new(-128).wrapping_shr(60), i14::new(-8));
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Saturating integer addition. Computes self + rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_add(i14::new(1)), i14::new(101));
assert_eq!(i14::MAX.saturating_add(i14::new(100)), i14::MAX);
assert_eq!(i14::MIN.saturating_add(i14::new(-1)), i14::MIN);
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Saturating integer subtraction. Computes self - rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_sub(i14::new(127)), i14::new(-27));
assert_eq!(i14::MIN.saturating_sub(i14::new(100)), i14::MIN);
assert_eq!(i14::MAX.saturating_sub(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_mul(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Saturating integer multiplication. Computes self * rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(10).saturating_mul(i14::new(12)), i14::new(120));
assert_eq!(i14::MAX.saturating_mul(i14::new(10)), i14::MAX);
assert_eq!(i14::MIN.saturating_mul(i14::new(10)), i14::MIN);
Sourcepub const fn saturating_div(self, rhs: Self) -> Self
pub const fn saturating_div(self, rhs: Self) -> Self
Saturating integer division. Computes self / rhs
, saturating at the numeric
bounds instead of overflowing.
§Panics
This function will panic if rhs is zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).saturating_div(i14::new(2)), i14::new(2));
assert_eq!(i14::MAX.saturating_div(i14::new(-1)), i14::MIN + i14::new(1));
assert_eq!(i14::MIN.saturating_div(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating integer negation. Computes -self
, returning MAX
if self == MIN
instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_neg(), i14::new(-100));
assert_eq!(i14::new(-100).saturating_neg(), i14::new(100));
assert_eq!(i14::MIN.saturating_neg(), i14::MAX);
assert_eq!(i14::MAX.saturating_neg(), i14::MIN + i14::new(1));
Sourcepub const fn saturating_pow(self, exp: u32) -> Self
pub const fn saturating_pow(self, exp: u32) -> Self
Saturating integer exponentiation. Computes self.pow(exp)
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(-4).saturating_pow(3), i14::new(-64));
assert_eq!(i14::MIN.saturating_pow(2), i14::MAX);
assert_eq!(i14::MIN.saturating_pow(3), i14::MIN);
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked integer addition. Computes self + rhs
, returning None
if overflow occurred.
§Examples
Basic usage:
assert_eq!((i14::MAX - i14::new(2)).checked_add(i14::new(1)), Some(i14::MAX - i14::new(1)));
assert_eq!((i14::MAX - i14::new(2)).checked_add(i14::new(3)), None);
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked integer subtraction. Computes self - rhs
, returning None
if overflow occurred.
§Examples
Basic usage:
assert_eq!((i14::MIN + i14::new(2)).checked_sub(i14::new(1)), Some(i14::MIN + i14::new(1)));
assert_eq!((i14::MIN + i14::new(2)).checked_sub(i14::new(3)), None);
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
Checked integer multiplication. Computes self * rhs
, returning None
if overflow occurred.
§Examples
Basic usage:
assert_eq!(i14::MAX.checked_mul(i14::new(1)), Some(i14::MAX));
assert_eq!(i14::MAX.checked_mul(i14::new(2)), None);
Sourcepub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
Checked integer division. Computes self / rhs
, returning None
if rhs == 0
or the division results in overflow.
§Examples
Basic usage:
assert_eq!((i14::MIN + i14::new(1)).checked_div(i14::new(-1)), Some(i14::new(8191)));
assert_eq!(i14::MIN.checked_div(i14::new(-1)), None);
assert_eq!((i14::new(1)).checked_div(i14::new(0)), None);
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Checked negation. Computes -self
, returning None
if self == MIN
.
§Examples
Basic usage:
assert_eq!(i14::new(5).checked_neg(), Some(i14::new(-5)));
assert_eq!(i14::MIN.checked_neg(), None);
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Checked shift left. Computes self << rhs
, returning None
if rhs
is larger than or
equal to the number of bits in self
.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).checked_shl(4), Some(i14::new(0x10)));
assert_eq!(i14::new(0x1).checked_shl(129), None);
assert_eq!(i14::new(0x10).checked_shl(13), Some(i14::new(0)));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Checked shift right. Computes self >> rhs
, returning None
if rhs
is larger than
or equal to the number of bits in self
.
§Examples
Basic usage:
assert_eq!(i14::new(0x10).checked_shr(4), Some(i14::new(0x1)));
assert_eq!(i14::new(0x10).checked_shr(129), None);
Sourcepub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_add(i14::new(2)), (i14::new(7), false));
assert_eq!(i14::MAX.overflowing_add(i14::new(1)), (i14::MIN, true));
Sourcepub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_sub(i14::new(2)), (i14::new(3), false));
assert_eq!(i14::MIN.overflowing_sub(i14::new(1)), (i14::MAX, true));
Sourcepub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_mul(i14::new(2)), (i14::new(10), false));
assert_eq!(i14::new(1_000).overflowing_mul(i14::new(10)), (i14::new(-6384), true));
Sourcepub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
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 zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_div(i14::new(2)), (i14::new(2), false));
assert_eq!(i14::MIN.overflowing_div(i14::new(-1)), (i14::MIN, true));
Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
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., i14::MIN
for values of type i14
),
then the minimum value will be returned again and true
will be returned for an overflow happening.
§Examples
Basic usage:
assert_eq!(i14::new(2).overflowing_neg(), (i14::new(-2), false));
assert_eq!(i14::MIN.overflowing_neg(), (i14::MIN, true));
Sourcepub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).overflowing_shl(4), (i14::new(0x10), false));
assert_eq!(i14::new(0x1).overflowing_shl(15), (i14::new(0x2), true));
assert_eq!(i14::new(0x10).overflowing_shl(13), (i14::new(0), false));
Sourcepub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x10).overflowing_shr(4), (i14::new(0x1), false));
assert_eq!(i14::new(0x10).overflowing_shr(15), (i14::new(0x8), true));
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true
if self
is positive and false
if the number is zero or negative.
§Examples
Basic usage:
assert!(i14::new(10).is_positive());
assert!(!i14::new(-10).is_positive());
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true
if self
is negative and false
if the number is zero or positive.
§Examples
Basic usage:
assert!(i14::new(-10).is_negative());
assert!(!i14::new(10).is_negative());
Sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
assert_eq!(i6::from_bits(0b10_1010).reverse_bits(), i6::from_bits(0b01_0101));
assert_eq!(i6::new(0), i6::new(0).reverse_bits());
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
.
§Examples
Basic usage:
let n = i6::from_bits(0b00_1000);
assert_eq!(n.count_ones(), 1);
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
.
§Examples
Basic usage:
assert_eq!(i6::MAX.count_zeros(), 1);
Sourcepub const fn leading_ones(self) -> u32
pub const fn leading_ones(self) -> u32
Returns the number of leading ones in the binary representation of self
.
§Examples
Basic usage:
let n = i6::new(-1);
assert_eq!(n.leading_ones(), 6);
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
.
§Examples
Basic usage:
let n = i6::new(-1);
assert_eq!(n.leading_zeros(), 0);
Sourcepub const fn trailing_ones(self) -> u32
pub const fn trailing_ones(self) -> u32
Returns the number of trailing ones in the binary representation of self
.
§Examples
Basic usage:
let n = i6::new(3);
assert_eq!(n.trailing_ones(), 2);
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
.
§Examples
Basic usage:
let n = i6::new(-4);
assert_eq!(n.trailing_zeros(), 2);
Sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_left(1), m);
Sourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_right(1), m);
Source§impl<const BITS: usize> Int<i16, BITS>
impl<const BITS: usize> Int<i16, BITS>
pub const MASK: i16
Sourcepub const fn new(value: i16) -> Self
pub const fn new(value: i16) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i8(value: i8) -> Self
pub const fn from_i8(value: i8) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i16(value: i16) -> Self
pub const fn from_i16(value: i16) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i32(value: i32) -> Self
pub const fn from_i32(value: i32) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i64(value: i64) -> Self
pub const fn from_i64(value: i64) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i128(value: i128) -> Self
pub const fn from_i128(value: i128) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn try_new(value: i16) -> Result<Self, TryNewError>
pub const fn try_new(value: i16) -> Result<Self, TryNewError>
Creates an instance or an error if the given value is outside of the valid range
Sourcepub const fn to_bits(self) -> u16
pub const fn to_bits(self) -> u16
Returns the bitwise representation of the value.
As the bit width is limited to BITS
the numeric value may differ from value
.
let value = i3::new(-1);
assert_eq!(value.to_bits(), 0b111); // 7
assert_eq!(value.value(), -1);
To convert from the bitwise representation back to an instance, use from_bits
.
Sourcepub const fn from_bits(value: u16) -> Self
pub const fn from_bits(value: u16) -> Self
Convert the bitwise representation from to_bits
to an instance.
let value = i3::from_bits(0b111);
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use new
.
§Panics
Panics if the given value exceeds the bit width specified by BITS
.
Sourcepub const fn try_from_bits(value: u16) -> Result<Self, TryNewError>
pub const fn try_from_bits(value: u16) -> Result<Self, TryNewError>
Tries to convert the bitwise representation from to_bits
to an instance.
i3::try_from_bits(0b1111).expect_err("value is > 3 bits");
let value = i3::try_from_bits(0b111).expect("value is <= 3 bits");
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use try_new
.
§Errors
Returns an error if the given value exceeds the bit width specified by BITS
.
Sourcepub const unsafe fn from_bits_unchecked(value: u16) -> Self
pub const unsafe fn from_bits_unchecked(value: u16) -> Self
Converts the bitwise representation from to_bits
to an instance,
without checking the bounds.
§Safety
The given value must not exceed the bit width specified by Self::BITS
.
Sourcepub const fn extract_i8(value: i8, start_bit: usize) -> Self
pub const fn extract_i8(value: i8, start_bit: usize) -> Self
Sourcepub const fn extract_u8(value: u8, start_bit: usize) -> Self
pub const fn extract_u8(value: u8, start_bit: usize) -> Self
Sourcepub const fn extract_i16(value: i16, start_bit: usize) -> Self
pub const fn extract_i16(value: i16, start_bit: usize) -> Self
Sourcepub const fn extract_u16(value: u16, start_bit: usize) -> Self
pub const fn extract_u16(value: u16, start_bit: usize) -> Self
Sourcepub const fn extract_i32(value: i32, start_bit: usize) -> Self
pub const fn extract_i32(value: i32, start_bit: usize) -> Self
Sourcepub const fn extract_u32(value: u32, start_bit: usize) -> Self
pub const fn extract_u32(value: u32, start_bit: usize) -> Self
Sourcepub const fn extract_i64(value: i64, start_bit: usize) -> Self
pub const fn extract_i64(value: i64, start_bit: usize) -> Self
Sourcepub const fn extract_u64(value: u64, start_bit: usize) -> Self
pub const fn extract_u64(value: u64, start_bit: usize) -> Self
Sourcepub const fn extract_i128(value: i128, start_bit: usize) -> Self
pub const fn extract_i128(value: i128, start_bit: usize) -> Self
Sourcepub const fn extract_u128(value: u128, start_bit: usize) -> Self
pub const fn extract_u128(value: u128, start_bit: usize) -> Self
Sourcepub const fn widen<const BITS_RESULT: usize>(self) -> Int<i16, BITS_RESULT>
pub const fn widen<const BITS_RESULT: usize>(self) -> Int<i16, BITS_RESULT>
Returns an Int
with a wider bit depth but with the same base data type
Sourcepub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
Sourcepub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
Sourcepub const fn wrapping_mul(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Sourcepub const fn wrapping_div(self, rhs: Self) -> Self
pub const fn wrapping_div(self, rhs: Self) -> Self
Wrapping (modular) division. Computes self / rhs
, wrapping around at the
boundary of the type.
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.
§Panics
This function will panic if rhs
is zero.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_div(i14::new(10)), i14::new(10));
assert_eq!(i14::MIN.wrapping_div(i14::new(-1)), i14::MIN);
Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self
, wrapping around at the boundary of the type.
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.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_neg(), i14::new(-100));
assert_eq!(i14::new(-100).wrapping_neg(), i14::new(100));
assert_eq!(i14::MIN.wrapping_neg(), i14::MIN);
Sourcepub const fn wrapping_shl(self, rhs: u32) -> Self
pub const fn wrapping_shl(self, rhs: u32) -> Self
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.
A rotate_left
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-1).wrapping_shl(7), i14::new(-128));
assert_eq!(i14::new(-1).wrapping_shl(128), i14::new(-4));
Sourcepub const fn wrapping_shr(self, rhs: u32) -> Self
pub const fn wrapping_shr(self, rhs: u32) -> Self
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.
A rotate_right
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-128).wrapping_shr(7), i14::new(-1));
assert_eq!(i14::new(-128).wrapping_shr(60), i14::new(-8));
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Saturating integer addition. Computes self + rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_add(i14::new(1)), i14::new(101));
assert_eq!(i14::MAX.saturating_add(i14::new(100)), i14::MAX);
assert_eq!(i14::MIN.saturating_add(i14::new(-1)), i14::MIN);
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Saturating integer subtraction. Computes self - rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_sub(i14::new(127)), i14::new(-27));
assert_eq!(i14::MIN.saturating_sub(i14::new(100)), i14::MIN);
assert_eq!(i14::MAX.saturating_sub(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_mul(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Saturating integer multiplication. Computes self * rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(10).saturating_mul(i14::new(12)), i14::new(120));
assert_eq!(i14::MAX.saturating_mul(i14::new(10)), i14::MAX);
assert_eq!(i14::MIN.saturating_mul(i14::new(10)), i14::MIN);
Sourcepub const fn saturating_div(self, rhs: Self) -> Self
pub const fn saturating_div(self, rhs: Self) -> Self
Saturating integer division. Computes self / rhs
, saturating at the numeric
bounds instead of overflowing.
§Panics
This function will panic if rhs is zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).saturating_div(i14::new(2)), i14::new(2));
assert_eq!(i14::MAX.saturating_div(i14::new(-1)), i14::MIN + i14::new(1));
assert_eq!(i14::MIN.saturating_div(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating integer negation. Computes -self
, returning MAX
if self == MIN
instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_neg(), i14::new(-100));
assert_eq!(i14::new(-100).saturating_neg(), i14::new(100));
assert_eq!(i14::MIN.saturating_neg(), i14::MAX);
assert_eq!(i14::MAX.saturating_neg(), i14::MIN + i14::new(1));
Sourcepub const fn saturating_pow(self, exp: u32) -> Self
pub const fn saturating_pow(self, exp: u32) -> Self
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
Checked integer division. Computes self / rhs
, returning None
if rhs == 0
or the division results in overflow.
§Examples
Basic usage:
assert_eq!((i14::MIN + i14::new(1)).checked_div(i14::new(-1)), Some(i14::new(8191)));
assert_eq!(i14::MIN.checked_div(i14::new(-1)), None);
assert_eq!((i14::new(1)).checked_div(i14::new(0)), None);
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Checked shift left. Computes self << rhs
, returning None
if rhs
is larger than or
equal to the number of bits in self
.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).checked_shl(4), Some(i14::new(0x10)));
assert_eq!(i14::new(0x1).checked_shl(129), None);
assert_eq!(i14::new(0x10).checked_shl(13), Some(i14::new(0)));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_add(i14::new(2)), (i14::new(7), false));
assert_eq!(i14::MAX.overflowing_add(i14::new(1)), (i14::MIN, true));
Sourcepub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_sub(i14::new(2)), (i14::new(3), false));
assert_eq!(i14::MIN.overflowing_sub(i14::new(1)), (i14::MAX, true));
Sourcepub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_mul(i14::new(2)), (i14::new(10), false));
assert_eq!(i14::new(1_000).overflowing_mul(i14::new(10)), (i14::new(-6384), true));
Sourcepub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
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 zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_div(i14::new(2)), (i14::new(2), false));
assert_eq!(i14::MIN.overflowing_div(i14::new(-1)), (i14::MIN, true));
Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
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., i14::MIN
for values of type i14
),
then the minimum value will be returned again and true
will be returned for an overflow happening.
§Examples
Basic usage:
assert_eq!(i14::new(2).overflowing_neg(), (i14::new(-2), false));
assert_eq!(i14::MIN.overflowing_neg(), (i14::MIN, true));
Sourcepub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).overflowing_shl(4), (i14::new(0x10), false));
assert_eq!(i14::new(0x1).overflowing_shl(15), (i14::new(0x2), true));
assert_eq!(i14::new(0x10).overflowing_shl(13), (i14::new(0), false));
Sourcepub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x10).overflowing_shr(4), (i14::new(0x1), false));
assert_eq!(i14::new(0x10).overflowing_shr(15), (i14::new(0x8), true));
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
assert_eq!(i6::from_bits(0b10_1010).reverse_bits(), i6::from_bits(0b01_0101));
assert_eq!(i6::new(0), i6::new(0).reverse_bits());
Sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Sourcepub const fn leading_ones(self) -> u32
pub const fn leading_ones(self) -> u32
Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Sourcepub const fn trailing_ones(self) -> u32
pub const fn trailing_ones(self) -> u32
Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_left(1), m);
Sourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_right(1), m);
Source§impl<const BITS: usize> Int<i32, BITS>
impl<const BITS: usize> Int<i32, BITS>
pub const MASK: i32
Sourcepub const fn new(value: i32) -> Self
pub const fn new(value: i32) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i8(value: i8) -> Self
pub const fn from_i8(value: i8) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i16(value: i16) -> Self
pub const fn from_i16(value: i16) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i32(value: i32) -> Self
pub const fn from_i32(value: i32) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i64(value: i64) -> Self
pub const fn from_i64(value: i64) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i128(value: i128) -> Self
pub const fn from_i128(value: i128) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn try_new(value: i32) -> Result<Self, TryNewError>
pub const fn try_new(value: i32) -> Result<Self, TryNewError>
Creates an instance or an error if the given value is outside of the valid range
Sourcepub const fn to_bits(self) -> u32
pub const fn to_bits(self) -> u32
Returns the bitwise representation of the value.
As the bit width is limited to BITS
the numeric value may differ from value
.
let value = i3::new(-1);
assert_eq!(value.to_bits(), 0b111); // 7
assert_eq!(value.value(), -1);
To convert from the bitwise representation back to an instance, use from_bits
.
Sourcepub const fn from_bits(value: u32) -> Self
pub const fn from_bits(value: u32) -> Self
Convert the bitwise representation from to_bits
to an instance.
let value = i3::from_bits(0b111);
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use new
.
§Panics
Panics if the given value exceeds the bit width specified by BITS
.
Sourcepub const fn try_from_bits(value: u32) -> Result<Self, TryNewError>
pub const fn try_from_bits(value: u32) -> Result<Self, TryNewError>
Tries to convert the bitwise representation from to_bits
to an instance.
i3::try_from_bits(0b1111).expect_err("value is > 3 bits");
let value = i3::try_from_bits(0b111).expect("value is <= 3 bits");
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use try_new
.
§Errors
Returns an error if the given value exceeds the bit width specified by BITS
.
Sourcepub const unsafe fn from_bits_unchecked(value: u32) -> Self
pub const unsafe fn from_bits_unchecked(value: u32) -> Self
Converts the bitwise representation from to_bits
to an instance,
without checking the bounds.
§Safety
The given value must not exceed the bit width specified by Self::BITS
.
Sourcepub const fn extract_i8(value: i8, start_bit: usize) -> Self
pub const fn extract_i8(value: i8, start_bit: usize) -> Self
Sourcepub const fn extract_u8(value: u8, start_bit: usize) -> Self
pub const fn extract_u8(value: u8, start_bit: usize) -> Self
Sourcepub const fn extract_i16(value: i16, start_bit: usize) -> Self
pub const fn extract_i16(value: i16, start_bit: usize) -> Self
Sourcepub const fn extract_u16(value: u16, start_bit: usize) -> Self
pub const fn extract_u16(value: u16, start_bit: usize) -> Self
Sourcepub const fn extract_i32(value: i32, start_bit: usize) -> Self
pub const fn extract_i32(value: i32, start_bit: usize) -> Self
Sourcepub const fn extract_u32(value: u32, start_bit: usize) -> Self
pub const fn extract_u32(value: u32, start_bit: usize) -> Self
Sourcepub const fn extract_i64(value: i64, start_bit: usize) -> Self
pub const fn extract_i64(value: i64, start_bit: usize) -> Self
Sourcepub const fn extract_u64(value: u64, start_bit: usize) -> Self
pub const fn extract_u64(value: u64, start_bit: usize) -> Self
Sourcepub const fn extract_i128(value: i128, start_bit: usize) -> Self
pub const fn extract_i128(value: i128, start_bit: usize) -> Self
Sourcepub const fn extract_u128(value: u128, start_bit: usize) -> Self
pub const fn extract_u128(value: u128, start_bit: usize) -> Self
Sourcepub const fn widen<const BITS_RESULT: usize>(self) -> Int<i32, BITS_RESULT>
pub const fn widen<const BITS_RESULT: usize>(self) -> Int<i32, BITS_RESULT>
Returns an Int
with a wider bit depth but with the same base data type
Sourcepub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
Sourcepub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
Sourcepub const fn wrapping_mul(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Sourcepub const fn wrapping_div(self, rhs: Self) -> Self
pub const fn wrapping_div(self, rhs: Self) -> Self
Wrapping (modular) division. Computes self / rhs
, wrapping around at the
boundary of the type.
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.
§Panics
This function will panic if rhs
is zero.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_div(i14::new(10)), i14::new(10));
assert_eq!(i14::MIN.wrapping_div(i14::new(-1)), i14::MIN);
Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self
, wrapping around at the boundary of the type.
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.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_neg(), i14::new(-100));
assert_eq!(i14::new(-100).wrapping_neg(), i14::new(100));
assert_eq!(i14::MIN.wrapping_neg(), i14::MIN);
Sourcepub const fn wrapping_shl(self, rhs: u32) -> Self
pub const fn wrapping_shl(self, rhs: u32) -> Self
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.
A rotate_left
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-1).wrapping_shl(7), i14::new(-128));
assert_eq!(i14::new(-1).wrapping_shl(128), i14::new(-4));
Sourcepub const fn wrapping_shr(self, rhs: u32) -> Self
pub const fn wrapping_shr(self, rhs: u32) -> Self
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.
A rotate_right
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-128).wrapping_shr(7), i14::new(-1));
assert_eq!(i14::new(-128).wrapping_shr(60), i14::new(-8));
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Saturating integer addition. Computes self + rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_add(i14::new(1)), i14::new(101));
assert_eq!(i14::MAX.saturating_add(i14::new(100)), i14::MAX);
assert_eq!(i14::MIN.saturating_add(i14::new(-1)), i14::MIN);
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Saturating integer subtraction. Computes self - rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_sub(i14::new(127)), i14::new(-27));
assert_eq!(i14::MIN.saturating_sub(i14::new(100)), i14::MIN);
assert_eq!(i14::MAX.saturating_sub(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_mul(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Saturating integer multiplication. Computes self * rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(10).saturating_mul(i14::new(12)), i14::new(120));
assert_eq!(i14::MAX.saturating_mul(i14::new(10)), i14::MAX);
assert_eq!(i14::MIN.saturating_mul(i14::new(10)), i14::MIN);
Sourcepub const fn saturating_div(self, rhs: Self) -> Self
pub const fn saturating_div(self, rhs: Self) -> Self
Saturating integer division. Computes self / rhs
, saturating at the numeric
bounds instead of overflowing.
§Panics
This function will panic if rhs is zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).saturating_div(i14::new(2)), i14::new(2));
assert_eq!(i14::MAX.saturating_div(i14::new(-1)), i14::MIN + i14::new(1));
assert_eq!(i14::MIN.saturating_div(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating integer negation. Computes -self
, returning MAX
if self == MIN
instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_neg(), i14::new(-100));
assert_eq!(i14::new(-100).saturating_neg(), i14::new(100));
assert_eq!(i14::MIN.saturating_neg(), i14::MAX);
assert_eq!(i14::MAX.saturating_neg(), i14::MIN + i14::new(1));
Sourcepub const fn saturating_pow(self, exp: u32) -> Self
pub const fn saturating_pow(self, exp: u32) -> Self
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
Checked integer division. Computes self / rhs
, returning None
if rhs == 0
or the division results in overflow.
§Examples
Basic usage:
assert_eq!((i14::MIN + i14::new(1)).checked_div(i14::new(-1)), Some(i14::new(8191)));
assert_eq!(i14::MIN.checked_div(i14::new(-1)), None);
assert_eq!((i14::new(1)).checked_div(i14::new(0)), None);
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Checked shift left. Computes self << rhs
, returning None
if rhs
is larger than or
equal to the number of bits in self
.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).checked_shl(4), Some(i14::new(0x10)));
assert_eq!(i14::new(0x1).checked_shl(129), None);
assert_eq!(i14::new(0x10).checked_shl(13), Some(i14::new(0)));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_add(i14::new(2)), (i14::new(7), false));
assert_eq!(i14::MAX.overflowing_add(i14::new(1)), (i14::MIN, true));
Sourcepub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_sub(i14::new(2)), (i14::new(3), false));
assert_eq!(i14::MIN.overflowing_sub(i14::new(1)), (i14::MAX, true));
Sourcepub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_mul(i14::new(2)), (i14::new(10), false));
assert_eq!(i14::new(1_000).overflowing_mul(i14::new(10)), (i14::new(-6384), true));
Sourcepub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
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 zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_div(i14::new(2)), (i14::new(2), false));
assert_eq!(i14::MIN.overflowing_div(i14::new(-1)), (i14::MIN, true));
Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
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., i14::MIN
for values of type i14
),
then the minimum value will be returned again and true
will be returned for an overflow happening.
§Examples
Basic usage:
assert_eq!(i14::new(2).overflowing_neg(), (i14::new(-2), false));
assert_eq!(i14::MIN.overflowing_neg(), (i14::MIN, true));
Sourcepub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).overflowing_shl(4), (i14::new(0x10), false));
assert_eq!(i14::new(0x1).overflowing_shl(15), (i14::new(0x2), true));
assert_eq!(i14::new(0x10).overflowing_shl(13), (i14::new(0), false));
Sourcepub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x10).overflowing_shr(4), (i14::new(0x1), false));
assert_eq!(i14::new(0x10).overflowing_shr(15), (i14::new(0x8), true));
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
assert_eq!(i6::from_bits(0b10_1010).reverse_bits(), i6::from_bits(0b01_0101));
assert_eq!(i6::new(0), i6::new(0).reverse_bits());
Sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Sourcepub const fn leading_ones(self) -> u32
pub const fn leading_ones(self) -> u32
Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Sourcepub const fn trailing_ones(self) -> u32
pub const fn trailing_ones(self) -> u32
Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_left(1), m);
Sourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_right(1), m);
Source§impl<const BITS: usize> Int<i64, BITS>
impl<const BITS: usize> Int<i64, BITS>
pub const MASK: i64
Sourcepub const fn new(value: i64) -> Self
pub const fn new(value: i64) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i8(value: i8) -> Self
pub const fn from_i8(value: i8) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i16(value: i16) -> Self
pub const fn from_i16(value: i16) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i32(value: i32) -> Self
pub const fn from_i32(value: i32) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i64(value: i64) -> Self
pub const fn from_i64(value: i64) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i128(value: i128) -> Self
pub const fn from_i128(value: i128) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn try_new(value: i64) -> Result<Self, TryNewError>
pub const fn try_new(value: i64) -> Result<Self, TryNewError>
Creates an instance or an error if the given value is outside of the valid range
Sourcepub const fn to_bits(self) -> u64
pub const fn to_bits(self) -> u64
Returns the bitwise representation of the value.
As the bit width is limited to BITS
the numeric value may differ from value
.
let value = i3::new(-1);
assert_eq!(value.to_bits(), 0b111); // 7
assert_eq!(value.value(), -1);
To convert from the bitwise representation back to an instance, use from_bits
.
Sourcepub const fn from_bits(value: u64) -> Self
pub const fn from_bits(value: u64) -> Self
Convert the bitwise representation from to_bits
to an instance.
let value = i3::from_bits(0b111);
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use new
.
§Panics
Panics if the given value exceeds the bit width specified by BITS
.
Sourcepub const fn try_from_bits(value: u64) -> Result<Self, TryNewError>
pub const fn try_from_bits(value: u64) -> Result<Self, TryNewError>
Tries to convert the bitwise representation from to_bits
to an instance.
i3::try_from_bits(0b1111).expect_err("value is > 3 bits");
let value = i3::try_from_bits(0b111).expect("value is <= 3 bits");
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use try_new
.
§Errors
Returns an error if the given value exceeds the bit width specified by BITS
.
Sourcepub const unsafe fn from_bits_unchecked(value: u64) -> Self
pub const unsafe fn from_bits_unchecked(value: u64) -> Self
Converts the bitwise representation from to_bits
to an instance,
without checking the bounds.
§Safety
The given value must not exceed the bit width specified by Self::BITS
.
Sourcepub const fn extract_i8(value: i8, start_bit: usize) -> Self
pub const fn extract_i8(value: i8, start_bit: usize) -> Self
Sourcepub const fn extract_u8(value: u8, start_bit: usize) -> Self
pub const fn extract_u8(value: u8, start_bit: usize) -> Self
Sourcepub const fn extract_i16(value: i16, start_bit: usize) -> Self
pub const fn extract_i16(value: i16, start_bit: usize) -> Self
Sourcepub const fn extract_u16(value: u16, start_bit: usize) -> Self
pub const fn extract_u16(value: u16, start_bit: usize) -> Self
Sourcepub const fn extract_i32(value: i32, start_bit: usize) -> Self
pub const fn extract_i32(value: i32, start_bit: usize) -> Self
Sourcepub const fn extract_u32(value: u32, start_bit: usize) -> Self
pub const fn extract_u32(value: u32, start_bit: usize) -> Self
Sourcepub const fn extract_i64(value: i64, start_bit: usize) -> Self
pub const fn extract_i64(value: i64, start_bit: usize) -> Self
Sourcepub const fn extract_u64(value: u64, start_bit: usize) -> Self
pub const fn extract_u64(value: u64, start_bit: usize) -> Self
Sourcepub const fn extract_i128(value: i128, start_bit: usize) -> Self
pub const fn extract_i128(value: i128, start_bit: usize) -> Self
Sourcepub const fn extract_u128(value: u128, start_bit: usize) -> Self
pub const fn extract_u128(value: u128, start_bit: usize) -> Self
Sourcepub const fn widen<const BITS_RESULT: usize>(self) -> Int<i64, BITS_RESULT>
pub const fn widen<const BITS_RESULT: usize>(self) -> Int<i64, BITS_RESULT>
Returns an Int
with a wider bit depth but with the same base data type
Sourcepub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
Sourcepub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
Sourcepub const fn wrapping_mul(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Sourcepub const fn wrapping_div(self, rhs: Self) -> Self
pub const fn wrapping_div(self, rhs: Self) -> Self
Wrapping (modular) division. Computes self / rhs
, wrapping around at the
boundary of the type.
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.
§Panics
This function will panic if rhs
is zero.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_div(i14::new(10)), i14::new(10));
assert_eq!(i14::MIN.wrapping_div(i14::new(-1)), i14::MIN);
Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self
, wrapping around at the boundary of the type.
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.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_neg(), i14::new(-100));
assert_eq!(i14::new(-100).wrapping_neg(), i14::new(100));
assert_eq!(i14::MIN.wrapping_neg(), i14::MIN);
Sourcepub const fn wrapping_shl(self, rhs: u32) -> Self
pub const fn wrapping_shl(self, rhs: u32) -> Self
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.
A rotate_left
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-1).wrapping_shl(7), i14::new(-128));
assert_eq!(i14::new(-1).wrapping_shl(128), i14::new(-4));
Sourcepub const fn wrapping_shr(self, rhs: u32) -> Self
pub const fn wrapping_shr(self, rhs: u32) -> Self
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.
A rotate_right
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-128).wrapping_shr(7), i14::new(-1));
assert_eq!(i14::new(-128).wrapping_shr(60), i14::new(-8));
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Saturating integer addition. Computes self + rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_add(i14::new(1)), i14::new(101));
assert_eq!(i14::MAX.saturating_add(i14::new(100)), i14::MAX);
assert_eq!(i14::MIN.saturating_add(i14::new(-1)), i14::MIN);
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Saturating integer subtraction. Computes self - rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_sub(i14::new(127)), i14::new(-27));
assert_eq!(i14::MIN.saturating_sub(i14::new(100)), i14::MIN);
assert_eq!(i14::MAX.saturating_sub(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_mul(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Saturating integer multiplication. Computes self * rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(10).saturating_mul(i14::new(12)), i14::new(120));
assert_eq!(i14::MAX.saturating_mul(i14::new(10)), i14::MAX);
assert_eq!(i14::MIN.saturating_mul(i14::new(10)), i14::MIN);
Sourcepub const fn saturating_div(self, rhs: Self) -> Self
pub const fn saturating_div(self, rhs: Self) -> Self
Saturating integer division. Computes self / rhs
, saturating at the numeric
bounds instead of overflowing.
§Panics
This function will panic if rhs is zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).saturating_div(i14::new(2)), i14::new(2));
assert_eq!(i14::MAX.saturating_div(i14::new(-1)), i14::MIN + i14::new(1));
assert_eq!(i14::MIN.saturating_div(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating integer negation. Computes -self
, returning MAX
if self == MIN
instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_neg(), i14::new(-100));
assert_eq!(i14::new(-100).saturating_neg(), i14::new(100));
assert_eq!(i14::MIN.saturating_neg(), i14::MAX);
assert_eq!(i14::MAX.saturating_neg(), i14::MIN + i14::new(1));
Sourcepub const fn saturating_pow(self, exp: u32) -> Self
pub const fn saturating_pow(self, exp: u32) -> Self
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
Checked integer division. Computes self / rhs
, returning None
if rhs == 0
or the division results in overflow.
§Examples
Basic usage:
assert_eq!((i14::MIN + i14::new(1)).checked_div(i14::new(-1)), Some(i14::new(8191)));
assert_eq!(i14::MIN.checked_div(i14::new(-1)), None);
assert_eq!((i14::new(1)).checked_div(i14::new(0)), None);
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Checked shift left. Computes self << rhs
, returning None
if rhs
is larger than or
equal to the number of bits in self
.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).checked_shl(4), Some(i14::new(0x10)));
assert_eq!(i14::new(0x1).checked_shl(129), None);
assert_eq!(i14::new(0x10).checked_shl(13), Some(i14::new(0)));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_add(i14::new(2)), (i14::new(7), false));
assert_eq!(i14::MAX.overflowing_add(i14::new(1)), (i14::MIN, true));
Sourcepub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_sub(i14::new(2)), (i14::new(3), false));
assert_eq!(i14::MIN.overflowing_sub(i14::new(1)), (i14::MAX, true));
Sourcepub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_mul(i14::new(2)), (i14::new(10), false));
assert_eq!(i14::new(1_000).overflowing_mul(i14::new(10)), (i14::new(-6384), true));
Sourcepub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
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 zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_div(i14::new(2)), (i14::new(2), false));
assert_eq!(i14::MIN.overflowing_div(i14::new(-1)), (i14::MIN, true));
Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
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., i14::MIN
for values of type i14
),
then the minimum value will be returned again and true
will be returned for an overflow happening.
§Examples
Basic usage:
assert_eq!(i14::new(2).overflowing_neg(), (i14::new(-2), false));
assert_eq!(i14::MIN.overflowing_neg(), (i14::MIN, true));
Sourcepub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).overflowing_shl(4), (i14::new(0x10), false));
assert_eq!(i14::new(0x1).overflowing_shl(15), (i14::new(0x2), true));
assert_eq!(i14::new(0x10).overflowing_shl(13), (i14::new(0), false));
Sourcepub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x10).overflowing_shr(4), (i14::new(0x1), false));
assert_eq!(i14::new(0x10).overflowing_shr(15), (i14::new(0x8), true));
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
assert_eq!(i6::from_bits(0b10_1010).reverse_bits(), i6::from_bits(0b01_0101));
assert_eq!(i6::new(0), i6::new(0).reverse_bits());
Sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Sourcepub const fn leading_ones(self) -> u32
pub const fn leading_ones(self) -> u32
Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Sourcepub const fn trailing_ones(self) -> u32
pub const fn trailing_ones(self) -> u32
Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_left(1), m);
Sourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_right(1), m);
Source§impl<const BITS: usize> Int<i128, BITS>
impl<const BITS: usize> Int<i128, BITS>
pub const MASK: i128
Sourcepub const fn new(value: i128) -> Self
pub const fn new(value: i128) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i8(value: i8) -> Self
pub const fn from_i8(value: i8) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i16(value: i16) -> Self
pub const fn from_i16(value: i16) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i32(value: i32) -> Self
pub const fn from_i32(value: i32) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i64(value: i64) -> Self
pub const fn from_i64(value: i64) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn from_i128(value: i128) -> Self
pub const fn from_i128(value: i128) -> Self
Creates an instance. Panics if the given value is outside of the valid range
Sourcepub const fn try_new(value: i128) -> Result<Self, TryNewError>
pub const fn try_new(value: i128) -> Result<Self, TryNewError>
Creates an instance or an error if the given value is outside of the valid range
Sourcepub const fn to_bits(self) -> u128
pub const fn to_bits(self) -> u128
Returns the bitwise representation of the value.
As the bit width is limited to BITS
the numeric value may differ from value
.
let value = i3::new(-1);
assert_eq!(value.to_bits(), 0b111); // 7
assert_eq!(value.value(), -1);
To convert from the bitwise representation back to an instance, use from_bits
.
Sourcepub const fn from_bits(value: u128) -> Self
pub const fn from_bits(value: u128) -> Self
Convert the bitwise representation from to_bits
to an instance.
let value = i3::from_bits(0b111);
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use new
.
§Panics
Panics if the given value exceeds the bit width specified by BITS
.
Sourcepub const fn try_from_bits(value: u128) -> Result<Self, TryNewError>
pub const fn try_from_bits(value: u128) -> Result<Self, TryNewError>
Tries to convert the bitwise representation from to_bits
to an instance.
i3::try_from_bits(0b1111).expect_err("value is > 3 bits");
let value = i3::try_from_bits(0b111).expect("value is <= 3 bits");
assert_eq!(value.value(), -1);
assert_eq!(value.to_bits(), 0b111);
If you want to convert a numeric value to an instance instead, use try_new
.
§Errors
Returns an error if the given value exceeds the bit width specified by BITS
.
Sourcepub const unsafe fn from_bits_unchecked(value: u128) -> Self
pub const unsafe fn from_bits_unchecked(value: u128) -> Self
Converts the bitwise representation from to_bits
to an instance,
without checking the bounds.
§Safety
The given value must not exceed the bit width specified by Self::BITS
.
Sourcepub const fn extract_i8(value: i8, start_bit: usize) -> Self
pub const fn extract_i8(value: i8, start_bit: usize) -> Self
Sourcepub const fn extract_u8(value: u8, start_bit: usize) -> Self
pub const fn extract_u8(value: u8, start_bit: usize) -> Self
Sourcepub const fn extract_i16(value: i16, start_bit: usize) -> Self
pub const fn extract_i16(value: i16, start_bit: usize) -> Self
Sourcepub const fn extract_u16(value: u16, start_bit: usize) -> Self
pub const fn extract_u16(value: u16, start_bit: usize) -> Self
Sourcepub const fn extract_i32(value: i32, start_bit: usize) -> Self
pub const fn extract_i32(value: i32, start_bit: usize) -> Self
Sourcepub const fn extract_u32(value: u32, start_bit: usize) -> Self
pub const fn extract_u32(value: u32, start_bit: usize) -> Self
Sourcepub const fn extract_i64(value: i64, start_bit: usize) -> Self
pub const fn extract_i64(value: i64, start_bit: usize) -> Self
Sourcepub const fn extract_u64(value: u64, start_bit: usize) -> Self
pub const fn extract_u64(value: u64, start_bit: usize) -> Self
Sourcepub const fn extract_i128(value: i128, start_bit: usize) -> Self
pub const fn extract_i128(value: i128, start_bit: usize) -> Self
Sourcepub const fn extract_u128(value: u128, start_bit: usize) -> Self
pub const fn extract_u128(value: u128, start_bit: usize) -> Self
Sourcepub const fn widen<const BITS_RESULT: usize>(self) -> Int<i128, BITS_RESULT>
pub const fn widen<const BITS_RESULT: usize>(self) -> Int<i128, BITS_RESULT>
Returns an Int
with a wider bit depth but with the same base data type
Sourcepub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
Sourcepub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
Sourcepub const fn wrapping_mul(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Sourcepub const fn wrapping_div(self, rhs: Self) -> Self
pub const fn wrapping_div(self, rhs: Self) -> Self
Wrapping (modular) division. Computes self / rhs
, wrapping around at the
boundary of the type.
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.
§Panics
This function will panic if rhs
is zero.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_div(i14::new(10)), i14::new(10));
assert_eq!(i14::MIN.wrapping_div(i14::new(-1)), i14::MIN);
Sourcepub const fn wrapping_neg(self) -> Self
pub const fn wrapping_neg(self) -> Self
Wrapping (modular) negation. Computes -self
, wrapping around at the boundary of the type.
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.
§Examples
Basic usage:
assert_eq!(i14::new(100).wrapping_neg(), i14::new(-100));
assert_eq!(i14::new(-100).wrapping_neg(), i14::new(100));
assert_eq!(i14::MIN.wrapping_neg(), i14::MIN);
Sourcepub const fn wrapping_shl(self, rhs: u32) -> Self
pub const fn wrapping_shl(self, rhs: u32) -> Self
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.
A rotate_left
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-1).wrapping_shl(7), i14::new(-128));
assert_eq!(i14::new(-1).wrapping_shl(128), i14::new(-4));
Sourcepub const fn wrapping_shr(self, rhs: u32) -> Self
pub const fn wrapping_shr(self, rhs: u32) -> Self
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.
A rotate_right
function exists as well, which may be what you
want instead.
§Examples
Basic usage:
assert_eq!(i14::new(-128).wrapping_shr(7), i14::new(-1));
assert_eq!(i14::new(-128).wrapping_shr(60), i14::new(-8));
Sourcepub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_add(self, rhs: Self) -> Self
Saturating integer addition. Computes self + rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_add(i14::new(1)), i14::new(101));
assert_eq!(i14::MAX.saturating_add(i14::new(100)), i14::MAX);
assert_eq!(i14::MIN.saturating_add(i14::new(-1)), i14::MIN);
Sourcepub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
Saturating integer subtraction. Computes self - rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_sub(i14::new(127)), i14::new(-27));
assert_eq!(i14::MIN.saturating_sub(i14::new(100)), i14::MIN);
assert_eq!(i14::MAX.saturating_sub(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_mul(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Saturating integer multiplication. Computes self * rhs
, saturating at the numeric
bounds instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(10).saturating_mul(i14::new(12)), i14::new(120));
assert_eq!(i14::MAX.saturating_mul(i14::new(10)), i14::MAX);
assert_eq!(i14::MIN.saturating_mul(i14::new(10)), i14::MIN);
Sourcepub const fn saturating_div(self, rhs: Self) -> Self
pub const fn saturating_div(self, rhs: Self) -> Self
Saturating integer division. Computes self / rhs
, saturating at the numeric
bounds instead of overflowing.
§Panics
This function will panic if rhs is zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).saturating_div(i14::new(2)), i14::new(2));
assert_eq!(i14::MAX.saturating_div(i14::new(-1)), i14::MIN + i14::new(1));
assert_eq!(i14::MIN.saturating_div(i14::new(-1)), i14::MAX);
Sourcepub const fn saturating_neg(self) -> Self
pub const fn saturating_neg(self) -> Self
Saturating integer negation. Computes -self
, returning MAX
if self == MIN
instead of overflowing.
§Examples
Basic usage:
assert_eq!(i14::new(100).saturating_neg(), i14::new(-100));
assert_eq!(i14::new(-100).saturating_neg(), i14::new(100));
assert_eq!(i14::MIN.saturating_neg(), i14::MAX);
assert_eq!(i14::MAX.saturating_neg(), i14::MIN + i14::new(1));
Sourcepub const fn saturating_pow(self, exp: u32) -> Self
pub const fn saturating_pow(self, exp: u32) -> Self
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
Checked integer division. Computes self / rhs
, returning None
if rhs == 0
or the division results in overflow.
§Examples
Basic usage:
assert_eq!((i14::MIN + i14::new(1)).checked_div(i14::new(-1)), Some(i14::new(8191)));
assert_eq!(i14::MIN.checked_div(i14::new(-1)), None);
assert_eq!((i14::new(1)).checked_div(i14::new(0)), None);
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Checked shift left. Computes self << rhs
, returning None
if rhs
is larger than or
equal to the number of bits in self
.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).checked_shl(4), Some(i14::new(0x10)));
assert_eq!(i14::new(0x1).checked_shl(129), None);
assert_eq!(i14::new(0x10).checked_shl(13), Some(i14::new(0)));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_add(i14::new(2)), (i14::new(7), false));
assert_eq!(i14::MAX.overflowing_add(i14::new(1)), (i14::MIN, true));
Sourcepub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_sub(i14::new(2)), (i14::new(3), false));
assert_eq!(i14::MIN.overflowing_sub(i14::new(1)), (i14::MAX, true));
Sourcepub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_mul(i14::new(2)), (i14::new(10), false));
assert_eq!(i14::new(1_000).overflowing_mul(i14::new(10)), (i14::new(-6384), true));
Sourcepub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)
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 zero.
§Examples
Basic usage:
assert_eq!(i14::new(5).overflowing_div(i14::new(2)), (i14::new(2), false));
assert_eq!(i14::MIN.overflowing_div(i14::new(-1)), (i14::MIN, true));
Sourcepub const fn overflowing_neg(self) -> (Self, bool)
pub const fn overflowing_neg(self) -> (Self, bool)
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., i14::MIN
for values of type i14
),
then the minimum value will be returned again and true
will be returned for an overflow happening.
§Examples
Basic usage:
assert_eq!(i14::new(2).overflowing_neg(), (i14::new(-2), false));
assert_eq!(i14::MIN.overflowing_neg(), (i14::MIN, true));
Sourcepub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x1).overflowing_shl(4), (i14::new(0x10), false));
assert_eq!(i14::new(0x1).overflowing_shl(15), (i14::new(0x2), true));
assert_eq!(i14::new(0x10).overflowing_shl(13), (i14::new(0), false));
Sourcepub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)
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.
§Examples
Basic usage:
assert_eq!(i14::new(0x10).overflowing_shr(4), (i14::new(0x1), false));
assert_eq!(i14::new(0x10).overflowing_shr(15), (i14::new(0x8), true));
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Sourcepub const fn reverse_bits(self) -> Self
pub const fn reverse_bits(self) -> Self
Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
Basic usage:
assert_eq!(i6::from_bits(0b10_1010).reverse_bits(), i6::from_bits(0b01_0101));
assert_eq!(i6::new(0), i6::new(0).reverse_bits());
Sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Sourcepub const fn leading_ones(self) -> u32
pub const fn leading_ones(self) -> u32
Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
Sourcepub const fn trailing_ones(self) -> u32
pub const fn trailing_ones(self) -> u32
Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Sourcepub const fn rotate_left(self, n: u32) -> Self
pub const fn rotate_left(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_left(1), m);
Sourcepub const fn rotate_right(self, n: u32) -> Self
pub const fn rotate_right(self, n: u32) -> Self
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!
§Examples
Basic usage:
let n = i6::from_bits(0b10_1010);
let m = i6::from_bits(0b01_0101);
assert_eq!(n.rotate_right(1), m);
Source§impl Int<i32, 24>
impl Int<i32, 24>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 3]
pub const fn to_be_bytes(self) -> [u8; 3]
pub const fn from_le_bytes(from: [u8; 3]) -> Self
pub const fn from_be_bytes(from: [u8; 3]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 3]
pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i64, 24>
impl Int<i64, 24>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 3]
pub const fn to_be_bytes(self) -> [u8; 3]
pub const fn from_le_bytes(from: [u8; 3]) -> Self
pub const fn from_be_bytes(from: [u8; 3]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 3]
pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 24>
impl Int<i128, 24>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 3]
pub const fn to_be_bytes(self) -> [u8; 3]
pub const fn from_le_bytes(from: [u8; 3]) -> Self
pub const fn from_be_bytes(from: [u8; 3]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 3]
pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i64, 40>
impl Int<i64, 40>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 5]
pub const fn to_be_bytes(self) -> [u8; 5]
pub const fn from_le_bytes(from: [u8; 5]) -> Self
pub const fn from_be_bytes(from: [u8; 5]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 5]
pub const fn from_ne_bytes(bytes: [u8; 5]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 40>
impl Int<i128, 40>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 5]
pub const fn to_be_bytes(self) -> [u8; 5]
pub const fn from_le_bytes(from: [u8; 5]) -> Self
pub const fn from_be_bytes(from: [u8; 5]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 5]
pub const fn from_ne_bytes(bytes: [u8; 5]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i64, 48>
impl Int<i64, 48>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 6]
pub const fn to_be_bytes(self) -> [u8; 6]
pub const fn from_le_bytes(from: [u8; 6]) -> Self
pub const fn from_be_bytes(from: [u8; 6]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 6]
pub const fn from_ne_bytes(bytes: [u8; 6]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 48>
impl Int<i128, 48>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 6]
pub const fn to_be_bytes(self) -> [u8; 6]
pub const fn from_le_bytes(from: [u8; 6]) -> Self
pub const fn from_be_bytes(from: [u8; 6]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 6]
pub const fn from_ne_bytes(bytes: [u8; 6]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i64, 56>
impl Int<i64, 56>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 7]
pub const fn to_be_bytes(self) -> [u8; 7]
pub const fn from_le_bytes(from: [u8; 7]) -> Self
pub const fn from_be_bytes(from: [u8; 7]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 7]
pub const fn from_ne_bytes(bytes: [u8; 7]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 56>
impl Int<i128, 56>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 7]
pub const fn to_be_bytes(self) -> [u8; 7]
pub const fn from_le_bytes(from: [u8; 7]) -> Self
pub const fn from_be_bytes(from: [u8; 7]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 7]
pub const fn from_ne_bytes(bytes: [u8; 7]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 72>
impl Int<i128, 72>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 9]
pub const fn to_be_bytes(self) -> [u8; 9]
pub const fn from_le_bytes(from: [u8; 9]) -> Self
pub const fn from_be_bytes(from: [u8; 9]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 9]
pub const fn from_ne_bytes(bytes: [u8; 9]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 80>
impl Int<i128, 80>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 10]
pub const fn to_be_bytes(self) -> [u8; 10]
pub const fn from_le_bytes(from: [u8; 10]) -> Self
pub const fn from_be_bytes(from: [u8; 10]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 10]
pub const fn from_ne_bytes(bytes: [u8; 10]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 88>
impl Int<i128, 88>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 11]
pub const fn to_be_bytes(self) -> [u8; 11]
pub const fn from_le_bytes(from: [u8; 11]) -> Self
pub const fn from_be_bytes(from: [u8; 11]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 11]
pub const fn from_ne_bytes(bytes: [u8; 11]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 96>
impl Int<i128, 96>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 12]
pub const fn to_be_bytes(self) -> [u8; 12]
pub const fn from_le_bytes(from: [u8; 12]) -> Self
pub const fn from_be_bytes(from: [u8; 12]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 12]
pub const fn from_ne_bytes(bytes: [u8; 12]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 104>
impl Int<i128, 104>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 13]
pub const fn to_be_bytes(self) -> [u8; 13]
pub const fn from_le_bytes(from: [u8; 13]) -> Self
pub const fn from_be_bytes(from: [u8; 13]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 13]
pub const fn from_ne_bytes(bytes: [u8; 13]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 112>
impl Int<i128, 112>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 14]
pub const fn to_be_bytes(self) -> [u8; 14]
pub const fn from_le_bytes(from: [u8; 14]) -> Self
pub const fn from_be_bytes(from: [u8; 14]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 14]
pub const fn from_ne_bytes(bytes: [u8; 14]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Source§impl Int<i128, 120>
impl Int<i128, 120>
Sourcepub const fn swap_bytes(self) -> Self
pub const fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
pub const fn to_le_bytes(self) -> [u8; 15]
pub const fn to_be_bytes(self) -> [u8; 15]
pub const fn from_le_bytes(from: [u8; 15]) -> Self
pub const fn from_be_bytes(from: [u8; 15]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 15]
pub const fn from_ne_bytes(bytes: [u8; 15]) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_le(value: Self) -> Self
pub const fn from_be(value: Self) -> Self
Trait Implementations§
Source§impl<T, const BITS: usize> AddAssign for Int<T, BITS>
impl<T, const BITS: usize> AddAssign for Int<T, BITS>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Binary for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Binary for Int<T, BITS>
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitAnd for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitAnd for Int<T, BITS>
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitAndAssign for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitAndAssign for Int<T, BITS>
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moreSource§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitOr for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitOr for Int<T, BITS>
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitOrAssign for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitOrAssign for Int<T, BITS>
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moreSource§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitXor for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitXor for Int<T, BITS>
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitXorAssign for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitXorAssign for Int<T, BITS>
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moreSource§impl<T: Clone + SignedInteger + BuiltinInteger, const BITS: usize> Clone for Int<T, BITS>
impl<T: Clone + SignedInteger + BuiltinInteger, const BITS: usize> Clone for Int<T, BITS>
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Debug for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Debug for Int<T, BITS>
Source§impl<T: Default + SignedInteger + BuiltinInteger, const BITS: usize> Default for Int<T, BITS>
impl<T: Default + SignedInteger + BuiltinInteger, const BITS: usize> Default for Int<T, BITS>
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Display for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Display for Int<T, BITS>
Source§impl<T, const BITS: usize> DivAssign for Int<T, BITS>
impl<T, const BITS: usize> DivAssign for Int<T, BITS>
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moreSource§impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i16, BITS>
impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i16, BITS>
Source§impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i32, BITS>
impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i32, BITS>
Source§impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i64, BITS>
impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i64, BITS>
Source§impl<const BITS: usize, const BITS_FROM: usize> From<Int<i16, BITS_FROM>> for Int<i128, BITS>
impl<const BITS: usize, const BITS_FROM: usize> From<Int<i16, BITS_FROM>> for Int<i128, BITS>
Source§impl<const BITS: usize, const BITS_FROM: usize> From<Int<i32, BITS_FROM>> for Int<i128, BITS>
impl<const BITS: usize, const BITS_FROM: usize> From<Int<i32, BITS_FROM>> for Int<i128, BITS>
Source§impl<const BITS: usize, const BITS_FROM: usize> From<Int<i64, BITS_FROM>> for Int<i128, BITS>
impl<const BITS: usize, const BITS_FROM: usize> From<Int<i64, BITS_FROM>> for Int<i128, BITS>
Source§impl<T: Hash + SignedInteger + BuiltinInteger, const BITS: usize> Hash for Int<T, BITS>
impl<T: Hash + SignedInteger + BuiltinInteger, const BITS: usize> Hash for Int<T, BITS>
Source§impl<const BITS: usize> Integer for Int<i128, BITS>
impl<const BITS: usize> Integer for Int<i128, BITS>
type UnderlyingType = i128
Source§type SignedInteger = Int<i128, BITS>
type SignedInteger = Int<i128, BITS>
Source§type UnsignedInteger = UInt<u128, BITS>
type UnsignedInteger = UInt<u128, BITS>
Source§fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
Source§fn new(value: i128) -> Self
fn new(value: i128) -> Self
Source§fn from_<T: Integer>(value: T) -> Self
fn from_<T: Integer>(value: T) -> Self
Self::new
for literals.Source§fn masked_new<T: Integer>(value: T) -> Self
fn masked_new<T: Integer>(value: T) -> Self
value
. Unlike the various new...
functions, this
will never fail as the value is masked to the result size.fn as_u8(self) -> u8
fn as_u16(self) -> u16
fn as_u32(self) -> u32
fn as_u64(self) -> u64
fn as_u128(self) -> u128
fn as_usize(self) -> usize
fn as_i8(self) -> i8
fn as_i16(self) -> i16
fn as_i32(self) -> i32
fn as_i64(self) -> i64
fn as_i128(self) -> i128
fn as_isize(self) -> isize
Source§fn to_unsigned(self) -> Self::UnsignedInteger
fn to_unsigned(self) -> Self::UnsignedInteger
Source§fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn value(self) -> i128
fn as_<T: Integer>(self) -> T
Source§impl<const BITS: usize> Integer for Int<i16, BITS>
impl<const BITS: usize> Integer for Int<i16, BITS>
type UnderlyingType = i16
Source§type SignedInteger = Int<i16, BITS>
type SignedInteger = Int<i16, BITS>
Source§type UnsignedInteger = UInt<u16, BITS>
type UnsignedInteger = UInt<u16, BITS>
Source§fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
Source§fn new(value: i16) -> Self
fn new(value: i16) -> Self
Source§fn from_<T: Integer>(value: T) -> Self
fn from_<T: Integer>(value: T) -> Self
Self::new
for literals.Source§fn masked_new<T: Integer>(value: T) -> Self
fn masked_new<T: Integer>(value: T) -> Self
value
. Unlike the various new...
functions, this
will never fail as the value is masked to the result size.fn as_u8(self) -> u8
fn as_u16(self) -> u16
fn as_u32(self) -> u32
fn as_u64(self) -> u64
fn as_u128(self) -> u128
fn as_usize(self) -> usize
fn as_i8(self) -> i8
fn as_i16(self) -> i16
fn as_i32(self) -> i32
fn as_i64(self) -> i64
fn as_i128(self) -> i128
fn as_isize(self) -> isize
Source§fn to_unsigned(self) -> Self::UnsignedInteger
fn to_unsigned(self) -> Self::UnsignedInteger
Source§fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn value(self) -> i16
fn as_<T: Integer>(self) -> T
Source§impl<const BITS: usize> Integer for Int<i32, BITS>
impl<const BITS: usize> Integer for Int<i32, BITS>
type UnderlyingType = i32
Source§type SignedInteger = Int<i32, BITS>
type SignedInteger = Int<i32, BITS>
Source§type UnsignedInteger = UInt<u32, BITS>
type UnsignedInteger = UInt<u32, BITS>
Source§fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
Source§fn new(value: i32) -> Self
fn new(value: i32) -> Self
Source§fn from_<T: Integer>(value: T) -> Self
fn from_<T: Integer>(value: T) -> Self
Self::new
for literals.Source§fn masked_new<T: Integer>(value: T) -> Self
fn masked_new<T: Integer>(value: T) -> Self
value
. Unlike the various new...
functions, this
will never fail as the value is masked to the result size.fn as_u8(self) -> u8
fn as_u16(self) -> u16
fn as_u32(self) -> u32
fn as_u64(self) -> u64
fn as_u128(self) -> u128
fn as_usize(self) -> usize
fn as_i8(self) -> i8
fn as_i16(self) -> i16
fn as_i32(self) -> i32
fn as_i64(self) -> i64
fn as_i128(self) -> i128
fn as_isize(self) -> isize
Source§fn to_unsigned(self) -> Self::UnsignedInteger
fn to_unsigned(self) -> Self::UnsignedInteger
Source§fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn value(self) -> i32
fn as_<T: Integer>(self) -> T
Source§impl<const BITS: usize> Integer for Int<i64, BITS>
impl<const BITS: usize> Integer for Int<i64, BITS>
type UnderlyingType = i64
Source§type SignedInteger = Int<i64, BITS>
type SignedInteger = Int<i64, BITS>
Source§type UnsignedInteger = UInt<u64, BITS>
type UnsignedInteger = UInt<u64, BITS>
Source§fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
Source§fn new(value: i64) -> Self
fn new(value: i64) -> Self
Source§fn from_<T: Integer>(value: T) -> Self
fn from_<T: Integer>(value: T) -> Self
Self::new
for literals.Source§fn masked_new<T: Integer>(value: T) -> Self
fn masked_new<T: Integer>(value: T) -> Self
value
. Unlike the various new...
functions, this
will never fail as the value is masked to the result size.fn as_u8(self) -> u8
fn as_u16(self) -> u16
fn as_u32(self) -> u32
fn as_u64(self) -> u64
fn as_u128(self) -> u128
fn as_usize(self) -> usize
fn as_i8(self) -> i8
fn as_i16(self) -> i16
fn as_i32(self) -> i32
fn as_i64(self) -> i64
fn as_i128(self) -> i128
fn as_isize(self) -> isize
Source§fn to_unsigned(self) -> Self::UnsignedInteger
fn to_unsigned(self) -> Self::UnsignedInteger
Source§fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn value(self) -> i64
fn as_<T: Integer>(self) -> T
Source§impl<const BITS: usize> Integer for Int<i8, BITS>
impl<const BITS: usize> Integer for Int<i8, BITS>
type UnderlyingType = i8
Source§type SignedInteger = Int<i8, BITS>
type SignedInteger = Int<i8, BITS>
Source§type UnsignedInteger = UInt<u8, BITS>
type UnsignedInteger = UInt<u8, BITS>
Source§fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
Source§fn new(value: i8) -> Self
fn new(value: i8) -> Self
Source§fn from_<T: Integer>(value: T) -> Self
fn from_<T: Integer>(value: T) -> Self
Self::new
for literals.Source§fn masked_new<T: Integer>(value: T) -> Self
fn masked_new<T: Integer>(value: T) -> Self
value
. Unlike the various new...
functions, this
will never fail as the value is masked to the result size.fn as_u8(self) -> u8
fn as_u16(self) -> u16
fn as_u32(self) -> u32
fn as_u64(self) -> u64
fn as_u128(self) -> u128
fn as_usize(self) -> usize
fn as_i8(self) -> i8
fn as_i16(self) -> i16
fn as_i32(self) -> i32
fn as_i64(self) -> i64
fn as_i128(self) -> i128
fn as_isize(self) -> isize
Source§fn to_unsigned(self) -> Self::UnsignedInteger
fn to_unsigned(self) -> Self::UnsignedInteger
Source§fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn from_unsigned(value: Self::UnsignedInteger) -> Self
fn value(self) -> i8
fn as_<T: Integer>(self) -> T
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> LowerHex for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> LowerHex for Int<T, BITS>
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> MulAssign for Int<T, BITS>where
Self: Integer,
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> MulAssign for Int<T, BITS>where
Self: Integer,
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moreSource§impl<T, const BITS: usize> Neg for Int<T, BITS>where
Self: Integer<UnderlyingType = T>,
T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,
impl<T, const BITS: usize> Neg for Int<T, BITS>where
Self: Integer<UnderlyingType = T>,
T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Not for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Not for Int<T, BITS>
Source§impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Octal for Int<T, BITS>
impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Octal for Int<T, BITS>
Source§impl<T: Ord + SignedInteger + BuiltinInteger, const BITS: usize> Ord for Int<T, BITS>
impl<T: Ord + SignedInteger + BuiltinInteger, const BITS: usize> Ord for Int<T, BITS>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq + SignedInteger + BuiltinInteger, const BITS: usize> PartialEq for Int<T, BITS>
impl<T: PartialEq + SignedInteger + BuiltinInteger, const BITS: usize> PartialEq for Int<T, BITS>
Source§impl<T: PartialOrd + SignedInteger + BuiltinInteger, const BITS: usize> PartialOrd for Int<T, BITS>
impl<T: PartialOrd + SignedInteger + BuiltinInteger, const BITS: usize> PartialOrd for Int<T, BITS>
Source§impl<'a, T: BuiltinInteger + SignedInteger, const BITS: usize> Product<&'a Int<T, BITS>> for Int<T, BITS>
impl<'a, T: BuiltinInteger + SignedInteger, const BITS: usize> Product<&'a Int<T, BITS>> for Int<T, BITS>
Source§impl<T: BuiltinInteger + SignedInteger, const BITS: usize> Product for Int<T, BITS>
impl<T: BuiltinInteger + SignedInteger, const BITS: usize> Product for Int<T, BITS>
Source§impl<T, TSHIFTBITS, const BITS: usize> Shl<TSHIFTBITS> for Int<T, BITS>where
T: Shl<TSHIFTBITS, Output = T> + Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,
TSHIFTBITS: TryInto<usize> + Copy,
impl<T, TSHIFTBITS, const BITS: usize> Shl<TSHIFTBITS> for Int<T, BITS>where
T: Shl<TSHIFTBITS, Output = T> + Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,
TSHIFTBITS: TryInto<usize> + Copy,
Source§impl<T, TSHIFTBITS, const BITS: usize> ShlAssign<TSHIFTBITS> for Int<T, BITS>
impl<T, TSHIFTBITS, const BITS: usize> ShlAssign<TSHIFTBITS> for Int<T, BITS>
Source§fn shl_assign(&mut self, rhs: TSHIFTBITS)
fn shl_assign(&mut self, rhs: TSHIFTBITS)
<<=
operation. Read moreSource§impl<T, TSHIFTBITS, const BITS: usize> ShrAssign<TSHIFTBITS> for Int<T, BITS>
impl<T, TSHIFTBITS, const BITS: usize> ShrAssign<TSHIFTBITS> for Int<T, BITS>
Source§fn shr_assign(&mut self, rhs: TSHIFTBITS)
fn shr_assign(&mut self, rhs: TSHIFTBITS)
>>=
operation. Read moreSource§impl<T, const BITS: usize> SubAssign for Int<T, BITS>
impl<T, const BITS: usize> SubAssign for Int<T, BITS>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more