Skip to main content

Int

Struct Int 

Source
pub struct Int<T: SignedInteger + BuiltinInteger, const BITS: usize> { /* private fields */ }
Expand description

A signed integer of arbitrary bit length.

§In-Memory Representation

The specific in-memory representation that would be seen by calling core::mem::transmute is unspecified. but satisfies the following guarantees:

  • An Int<T, BITS> has the same size/alignment as T
  • An Int has no uninitialized bytes or padding (satisfies bytemuck::NoUninit).
  • If the value of a Int<T, BITS> is non-negative, then it will the same representation as UInt<T, BITS>

When cfg(feature = "bytemuck") is enabled, the appropriate traits are implemented based on the above guarantees. It is not possible to implement bytemuck::Contiguous because that would be incompatible with a zero-extended memory representation.

Since the underlying representation is unspecified, it may change in a patch version without being considered a breaking change.

Implementations§

Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Int<T, BITS>

Source

pub const BITS: usize = BITS

Source

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.

Source

pub const unsafe fn new_unchecked(value: T) -> Self

Initializes a new value without checking the bounds

§Safety

Must only be called with a value bigger or equal to Self::MIN and less than or equal to Self::MAX.

Source§

impl<const BITS: usize> Int<i8, BITS>

Source

pub const MASK: i8

Source

pub const fn new(value: i8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i8(value: i8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i16(value: i16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i32(value: i32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i64(value: i64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i128(value: i128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

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

Source

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));
Source

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);
Source

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));
Source

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);
Source

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);
Source

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));
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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)));
Source

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);
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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());
Source

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());
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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>

Source

pub const MASK: i16

Source

pub const fn new(value: i16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i8(value: i8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i16(value: i16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i32(value: i32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i64(value: i64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i128(value: i128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

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

Source

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));
Source

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);
Source

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));
Source

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);
Source

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);
Source

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));
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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)));
Source

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);
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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());
Source

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());
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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>

Source

pub const MASK: i32

Source

pub const fn new(value: i32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i8(value: i8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i16(value: i16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i32(value: i32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i64(value: i64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i128(value: i128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

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

Source

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));
Source

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);
Source

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));
Source

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);
Source

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);
Source

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));
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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)));
Source

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);
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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());
Source

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());
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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>

Source

pub const MASK: i64

Source

pub const fn new(value: i64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i8(value: i8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i16(value: i16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i32(value: i32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i64(value: i64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i128(value: i128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

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

Source

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));
Source

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);
Source

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));
Source

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);
Source

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);
Source

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));
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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)));
Source

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);
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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());
Source

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());
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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>

Source

pub const MASK: i128

Source

pub const fn new(value: i128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i8(value: i8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i16(value: i16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i32(value: i32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i64(value: i64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_i128(value: i128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: from_bits(value >> start_bit). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

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

Source

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));
Source

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);
Source

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));
Source

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);
Source

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);
Source

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));
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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)));
Source

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);
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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());
Source

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());
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 3]

Source

pub const fn to_be_bytes(self) -> [u8; 3]

Source

pub const fn from_le_bytes(from: [u8; 3]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 3]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 3]

Source

pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i64, 24>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 3]

Source

pub const fn to_be_bytes(self) -> [u8; 3]

Source

pub const fn from_le_bytes(from: [u8; 3]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 3]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 3]

Source

pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 24>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 3]

Source

pub const fn to_be_bytes(self) -> [u8; 3]

Source

pub const fn from_le_bytes(from: [u8; 3]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 3]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 3]

Source

pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i64, 40>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 5]

Source

pub const fn to_be_bytes(self) -> [u8; 5]

Source

pub const fn from_le_bytes(from: [u8; 5]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 5]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 5]

Source

pub const fn from_ne_bytes(bytes: [u8; 5]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 40>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 5]

Source

pub const fn to_be_bytes(self) -> [u8; 5]

Source

pub const fn from_le_bytes(from: [u8; 5]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 5]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 5]

Source

pub const fn from_ne_bytes(bytes: [u8; 5]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i64, 48>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 6]

Source

pub const fn to_be_bytes(self) -> [u8; 6]

Source

pub const fn from_le_bytes(from: [u8; 6]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 6]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 6]

Source

pub const fn from_ne_bytes(bytes: [u8; 6]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 48>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 6]

Source

pub const fn to_be_bytes(self) -> [u8; 6]

Source

pub const fn from_le_bytes(from: [u8; 6]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 6]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 6]

Source

pub const fn from_ne_bytes(bytes: [u8; 6]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i64, 56>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 7]

Source

pub const fn to_be_bytes(self) -> [u8; 7]

Source

pub const fn from_le_bytes(from: [u8; 7]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 7]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 7]

Source

pub const fn from_ne_bytes(bytes: [u8; 7]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 56>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 7]

Source

pub const fn to_be_bytes(self) -> [u8; 7]

Source

pub const fn from_le_bytes(from: [u8; 7]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 7]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 7]

Source

pub const fn from_ne_bytes(bytes: [u8; 7]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 72>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 9]

Source

pub const fn to_be_bytes(self) -> [u8; 9]

Source

pub const fn from_le_bytes(from: [u8; 9]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 9]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 9]

Source

pub const fn from_ne_bytes(bytes: [u8; 9]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 80>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 10]

Source

pub const fn to_be_bytes(self) -> [u8; 10]

Source

pub const fn from_le_bytes(from: [u8; 10]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 10]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 10]

Source

pub const fn from_ne_bytes(bytes: [u8; 10]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 88>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 11]

Source

pub const fn to_be_bytes(self) -> [u8; 11]

Source

pub const fn from_le_bytes(from: [u8; 11]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 11]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 11]

Source

pub const fn from_ne_bytes(bytes: [u8; 11]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 96>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 12]

Source

pub const fn to_be_bytes(self) -> [u8; 12]

Source

pub const fn from_le_bytes(from: [u8; 12]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 12]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 12]

Source

pub const fn from_ne_bytes(bytes: [u8; 12]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 104>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 13]

Source

pub const fn to_be_bytes(self) -> [u8; 13]

Source

pub const fn from_le_bytes(from: [u8; 13]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 13]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 13]

Source

pub const fn from_ne_bytes(bytes: [u8; 13]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 112>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 14]

Source

pub const fn to_be_bytes(self) -> [u8; 14]

Source

pub const fn from_le_bytes(from: [u8; 14]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 14]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 14]

Source

pub const fn from_ne_bytes(bytes: [u8; 14]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl Int<i128, 120>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 15]

Source

pub const fn to_be_bytes(self) -> [u8; 15]

Source

pub const fn from_le_bytes(from: [u8; 15]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 15]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 15]

Source

pub const fn from_ne_bytes(bytes: [u8; 15]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Trait Implementations§

Source§

impl<T, const BITS: usize> Add for Int<T, BITS>
where T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,

Source§

type Output = Int<T, BITS>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, const BITS: usize> AddAssign for Int<T, BITS>
where T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Binary for Int<T, BITS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitAnd for Int<T, BITS>

Source§

type Output = Int<T, BITS>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitAndAssign for Int<T, BITS>

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitOr for Int<T, BITS>

Source§

type Output = Int<T, BITS>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitOrAssign for Int<T, BITS>

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitXor for Int<T, BITS>

Source§

type Output = Int<T, BITS>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> BitXorAssign for Int<T, BITS>

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl<T: Clone + SignedInteger + BuiltinInteger, const BITS: usize> Clone for Int<T, BITS>

Source§

fn clone(&self) -> Int<T, BITS>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Debug for Int<T, BITS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + SignedInteger + BuiltinInteger, const BITS: usize> Default for Int<T, BITS>

Source§

fn default() -> Int<T, BITS>

Returns the “default value” for a type. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Display for Int<T, BITS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const BITS: usize> Div for Int<T, BITS>
where T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,

Source§

type Output = Int<T, BITS>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<T, const BITS: usize> DivAssign for Int<T, BITS>
where T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<const BITS: usize> From<Int<i128, BITS>> for i128

Source§

fn from(from: Int<i128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i128, BITS>> for i16

Source§

fn from(from: Int<i128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i128, BITS>> for i32

Source§

fn from(from: Int<i128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i128, BITS>> for i64

Source§

fn from(from: Int<i128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i128, BITS>> for i8

Source§

fn from(from: Int<i128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i16, BITS>

Source§

fn from(item: Int<i128, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i32, BITS>

Source§

fn from(item: Int<i128, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i64, BITS>

Source§

fn from(item: Int<i128, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i128, BITS_FROM>> for Int<i8, BITS>

Source§

fn from(item: Int<i128, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i16, BITS>> for i128

Source§

fn from(from: Int<i16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i16, BITS>> for i16

Source§

fn from(from: Int<i16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i16, BITS>> for i32

Source§

fn from(from: Int<i16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i16, BITS>> for i64

Source§

fn from(from: Int<i16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i16, BITS>> for i8

Source§

fn from(from: Int<i16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i16, BITS_FROM>> for Int<i128, BITS>

Source§

fn from(item: Int<i16, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i16, BITS_FROM>> for Int<i32, BITS>

Source§

fn from(item: Int<i16, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i16, BITS_FROM>> for Int<i64, BITS>

Source§

fn from(item: Int<i16, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i16, BITS_FROM>> for Int<i8, BITS>

Source§

fn from(item: Int<i16, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i32, BITS>> for i128

Source§

fn from(from: Int<i32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i32, BITS>> for i16

Source§

fn from(from: Int<i32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i32, BITS>> for i32

Source§

fn from(from: Int<i32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i32, BITS>> for i64

Source§

fn from(from: Int<i32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i32, BITS>> for i8

Source§

fn from(from: Int<i32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i32, BITS_FROM>> for Int<i128, BITS>

Source§

fn from(item: Int<i32, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i32, BITS_FROM>> for Int<i16, BITS>

Source§

fn from(item: Int<i32, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i32, BITS_FROM>> for Int<i64, BITS>

Source§

fn from(item: Int<i32, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i32, BITS_FROM>> for Int<i8, BITS>

Source§

fn from(item: Int<i32, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i64, BITS>> for i128

Source§

fn from(from: Int<i64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i64, BITS>> for i16

Source§

fn from(from: Int<i64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i64, BITS>> for i32

Source§

fn from(from: Int<i64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i64, BITS>> for i64

Source§

fn from(from: Int<i64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i64, BITS>> for i8

Source§

fn from(from: Int<i64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i64, BITS_FROM>> for Int<i128, BITS>

Source§

fn from(item: Int<i64, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i64, BITS_FROM>> for Int<i16, BITS>

Source§

fn from(item: Int<i64, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i64, BITS_FROM>> for Int<i32, BITS>

Source§

fn from(item: Int<i64, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i64, BITS_FROM>> for Int<i8, BITS>

Source§

fn from(item: Int<i64, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i8, BITS>> for i128

Source§

fn from(from: Int<i8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i8, BITS>> for i16

Source§

fn from(from: Int<i8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i8, BITS>> for i32

Source§

fn from(from: Int<i8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i8, BITS>> for i64

Source§

fn from(from: Int<i8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<Int<i8, BITS>> for i8

Source§

fn from(from: Int<i8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i8, BITS_FROM>> for Int<i128, BITS>

Source§

fn from(item: Int<i8, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i8, BITS_FROM>> for Int<i16, BITS>

Source§

fn from(item: Int<i8, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i8, BITS_FROM>> for Int<i32, BITS>

Source§

fn from(item: Int<i8, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<Int<i8, BITS_FROM>> for Int<i64, BITS>

Source§

fn from(item: Int<i8, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i128> for Int<i128, BITS>

Source§

fn from(from: i128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i128> for Int<i16, BITS>

Source§

fn from(from: i128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i128> for Int<i32, BITS>

Source§

fn from(from: i128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i128> for Int<i64, BITS>

Source§

fn from(from: i128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i128> for Int<i8, BITS>

Source§

fn from(from: i128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i16> for Int<i128, BITS>

Source§

fn from(from: i16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i16> for Int<i16, BITS>

Source§

fn from(from: i16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i16> for Int<i32, BITS>

Source§

fn from(from: i16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i16> for Int<i64, BITS>

Source§

fn from(from: i16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i16> for Int<i8, BITS>

Source§

fn from(from: i16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i32> for Int<i128, BITS>

Source§

fn from(from: i32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i32> for Int<i16, BITS>

Source§

fn from(from: i32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i32> for Int<i32, BITS>

Source§

fn from(from: i32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i32> for Int<i64, BITS>

Source§

fn from(from: i32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i32> for Int<i8, BITS>

Source§

fn from(from: i32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i64> for Int<i128, BITS>

Source§

fn from(from: i64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i64> for Int<i16, BITS>

Source§

fn from(from: i64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i64> for Int<i32, BITS>

Source§

fn from(from: i64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i64> for Int<i64, BITS>

Source§

fn from(from: i64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i64> for Int<i8, BITS>

Source§

fn from(from: i64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i8> for Int<i128, BITS>

Source§

fn from(from: i8) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i8> for Int<i16, BITS>

Source§

fn from(from: i8) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i8> for Int<i32, BITS>

Source§

fn from(from: i8) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i8> for Int<i64, BITS>

Source§

fn from(from: i8) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<i8> for Int<i8, BITS>

Source§

fn from(from: i8) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + SignedInteger + BuiltinInteger, const BITS: usize> Hash for Int<T, BITS>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const BITS: usize> Integer for Int<i128, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

const IS_SIGNED: bool = true

Source§

type UnderlyingType = i128

Source§

type SignedInteger = Int<i128, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u128, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: i128) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size. Read more
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> i128

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<const BITS: usize> Integer for Int<i16, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

const IS_SIGNED: bool = true

Source§

type UnderlyingType = i16

Source§

type SignedInteger = Int<i16, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u16, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: i16) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size. Read more
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> i16

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<const BITS: usize> Integer for Int<i32, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

const IS_SIGNED: bool = true

Source§

type UnderlyingType = i32

Source§

type SignedInteger = Int<i32, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u32, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: i32) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size. Read more
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> i32

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<const BITS: usize> Integer for Int<i64, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

const IS_SIGNED: bool = true

Source§

type UnderlyingType = i64

Source§

type SignedInteger = Int<i64, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u64, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: i64) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size. Read more
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> i64

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<const BITS: usize> Integer for Int<i8, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

const IS_SIGNED: bool = true

Source§

type UnderlyingType = i8

Source§

type SignedInteger = Int<i8, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u8, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: i8) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size. Read more
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> i8

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> LowerHex for Int<T, BITS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const BITS: usize> Mul for Int<T, BITS>
where T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,

Source§

type Output = Int<T, BITS>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> MulAssign for Int<T, BITS>
where Self: Integer,

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

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§

type Output = Int<T, BITS>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Not for Int<T, BITS>

Source§

type Output = Int<T, BITS>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> Octal for Int<T, BITS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Ord + SignedInteger + BuiltinInteger, const BITS: usize> Ord for Int<T, BITS>

Source§

fn cmp(&self, other: &Int<T, BITS>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + SignedInteger + BuiltinInteger, const BITS: usize> PartialEq for Int<T, BITS>

Source§

fn eq(&self, other: &Int<T, BITS>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + SignedInteger + BuiltinInteger, const BITS: usize> PartialOrd for Int<T, BITS>

Source§

fn partial_cmp(&self, other: &Int<T, BITS>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T: BuiltinInteger + SignedInteger, const BITS: usize> Product<&'a Int<T, BITS>> for Int<T, BITS>
where Self: Integer + Mul<Output = Self>,

Source§

fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<T: BuiltinInteger + SignedInteger, const BITS: usize> Product for Int<T, BITS>
where Self: Integer + Mul<Output = Self>,

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
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,

Source§

type Output = Int<T, BITS>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: TSHIFTBITS) -> Self::Output

Performs the << operation. Read more
Source§

impl<T, TSHIFTBITS, const BITS: usize> ShlAssign<TSHIFTBITS> for Int<T, BITS>
where Self: Integer, T: Shl<TSHIFTBITS, Output = T> + Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger, TSHIFTBITS: TryInto<usize> + Copy,

Source§

fn shl_assign(&mut self, rhs: TSHIFTBITS)

Performs the <<= operation. Read more
Source§

impl<T, TSHIFTBITS, const BITS: usize> Shr<TSHIFTBITS> for Int<T, BITS>
where Self: Integer, T: Shr<TSHIFTBITS, Output = T> + Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger, TSHIFTBITS: TryInto<usize> + Copy,

Source§

type Output = Int<T, BITS>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: TSHIFTBITS) -> Self::Output

Performs the >> operation. Read more
Source§

impl<T, TSHIFTBITS, const BITS: usize> ShrAssign<TSHIFTBITS> for Int<T, BITS>
where Self: Integer, T: Shr<TSHIFTBITS, Output = T> + Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger, TSHIFTBITS: TryInto<usize> + Copy,

Source§

fn shr_assign(&mut self, rhs: TSHIFTBITS)

Performs the >>= operation. Read more
Source§

impl<T, const BITS: usize> Sub for Int<T, BITS>
where T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,

Source§

type Output = Int<T, BITS>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, const BITS: usize> SubAssign for Int<T, BITS>
where T: Shl<usize, Output = T> + Shr<usize, Output = T> + SignedInteger + BuiltinInteger,

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<'a, T: BuiltinInteger + SignedInteger, const BITS: usize> Sum<&'a Int<T, BITS>> for Int<T, BITS>
where Self: Integer + Default + Add<Output = Self>,

Source§

fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T: BuiltinInteger + SignedInteger, const BITS: usize> Sum for Int<T, BITS>
where Self: Integer + Default + Add<Output = Self>,

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> UpperHex for Int<T, BITS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy + SignedInteger + BuiltinInteger, const BITS: usize> Copy for Int<T, BITS>

Source§

impl<T: Eq + SignedInteger + BuiltinInteger, const BITS: usize> Eq for Int<T, BITS>

Source§

impl<const BITS: usize> SignedInteger for Int<i128, BITS>

Source§

impl<const BITS: usize> SignedInteger for Int<i16, BITS>

Source§

impl<const BITS: usize> SignedInteger for Int<i32, BITS>

Source§

impl<const BITS: usize> SignedInteger for Int<i64, BITS>

Source§

impl<const BITS: usize> SignedInteger for Int<i8, BITS>

Source§

impl<T: SignedInteger + BuiltinInteger, const BITS: usize> StructuralPartialEq for Int<T, BITS>

Auto Trait Implementations§

§

impl<T, const BITS: usize> Freeze for Int<T, BITS>
where T: Freeze,

§

impl<T, const BITS: usize> RefUnwindSafe for Int<T, BITS>
where T: RefUnwindSafe,

§

impl<T, const BITS: usize> Send for Int<T, BITS>
where T: Send,

§

impl<T, const BITS: usize> Sync for Int<T, BITS>
where T: Sync,

§

impl<T, const BITS: usize> Unpin for Int<T, BITS>
where T: Unpin,

§

impl<T, const BITS: usize> UnwindSafe for Int<T, BITS>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.