pub struct BitInt<T: Signed + PrimInt, const N: u32>(/* private fields */);
Expand description
BitInt
is a type that represents a N
-bit signed integer.
N
is the number of bits in the value, including the sign bit. The largest
size of N
is equal to the size of the underlying type in bits.
§Examples
type Int = BitInt<i8, 7>;
let n = Int::new(-64).unwrap();
assert_eq!(n, Int::MIN);
assert_eq!(n.checked_sub(1), None);
assert_eq!(n.get().checked_sub(1), Some(-65));
In this case, N
must be less than or equal to i32::BITS
:
let _ = BitInt::<i32, 33>::new(42);
N
must be greater than 0
:
let _ = BitInt::<i64, 0>::new(0);
Implementations§
Source§impl<const N: u32> BitInt<i8, N>
impl<const N: u32> BitInt<i8, N>
Source§impl<const N: u32> BitInt<i16, N>
impl<const N: u32> BitInt<i16, N>
Source§impl<const N: u32> BitInt<i32, N>
impl<const N: u32> BitInt<i32, N>
Source§impl<const N: u32> BitInt<i64, N>
impl<const N: u32> BitInt<i64, N>
Source§impl<const N: u32> BitInt<i128, N>
impl<const N: u32> BitInt<i128, N>
Source§impl<const N: u32> BitInt<isize, N>
impl<const N: u32> BitInt<isize, N>
Source§impl<const N: u32> BitInt<i8, N>
impl<const N: u32> BitInt<i8, N>
Sourcepub const fn checked_add(self, rhs: i8) -> Option<Self>
pub const fn checked_add(self, rhs: i8) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: i8) -> Option<Self>
pub const fn checked_sub(self, rhs: i8) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: i8) -> Option<Self>
pub const fn checked_mul(self, rhs: i8) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: i8) -> Option<Self>
pub const fn checked_div(self, rhs: i8) -> Option<Self>
Calculates the divisor when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i8, 7>::new(42).unwrap();
assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i8, 7>::MIN.checked_div(-1), None);
Sourcepub const fn checked_div_euclid(self, rhs: i8) -> Option<Self>
pub const fn checked_div_euclid(self, rhs: i8) -> Option<Self>
Calculates the quotient of Euclidean division of self
by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i8, 7>::new(42).unwrap();
assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i8, 7>::MIN.checked_div_euclid(-1), None);
Sourcepub const fn checked_rem(self, rhs: i8) -> Option<Self>
pub const fn checked_rem(self, rhs: i8) -> Option<Self>
Calculates the remainder when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i8, 4>::new(5).unwrap();
assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i8, 4>::MIN.checked_rem(-1), None);
Sourcepub const fn checked_rem_euclid(self, rhs: i8) -> Option<Self>
pub const fn checked_rem_euclid(self, rhs: i8) -> Option<Self>
Calculates the multiplication of self
and rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i8, 4>::new(5).unwrap();
assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i8, 4>::MIN.checked_rem_euclid(-1), None);
Sourcepub const fn checked_ilog(self, base: i8) -> Option<u32>
pub const fn checked_ilog(self, base: i8) -> Option<u32>
Sourcepub const fn checked_ilog2(self) -> Option<u32>
pub const fn checked_ilog2(self) -> Option<u32>
Sourcepub const fn checked_ilog10(self) -> Option<u32>
pub const fn checked_ilog10(self) -> Option<u32>
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Shifts self
left by rhs
bits.
Returns None
if rhs
is larger than or equal to the number of bits
in self
.
§Examples
let n = BitInt::<i8, 6>::new(0x01).unwrap();
let m = BitInt::<i8, 6>::new(0x10).unwrap();
assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i8::BITS - 1).map(BitInt::get), Some(0x00));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
Sourcepub const fn checked_pow(self, exp: u32) -> Option<Self>
pub const fn checked_pow(self, exp: u32) -> Option<Self>
Source§impl<const N: u32> BitInt<i16, N>
impl<const N: u32> BitInt<i16, N>
Sourcepub const fn checked_add(self, rhs: i16) -> Option<Self>
pub const fn checked_add(self, rhs: i16) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: i16) -> Option<Self>
pub const fn checked_sub(self, rhs: i16) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: i16) -> Option<Self>
pub const fn checked_mul(self, rhs: i16) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: i16) -> Option<Self>
pub const fn checked_div(self, rhs: i16) -> Option<Self>
Calculates the divisor when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i16, 7>::new(42).unwrap();
assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i16, 7>::MIN.checked_div(-1), None);
Sourcepub const fn checked_div_euclid(self, rhs: i16) -> Option<Self>
pub const fn checked_div_euclid(self, rhs: i16) -> Option<Self>
Calculates the quotient of Euclidean division of self
by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i16, 7>::new(42).unwrap();
assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i16, 7>::MIN.checked_div_euclid(-1), None);
Sourcepub const fn checked_rem(self, rhs: i16) -> Option<Self>
pub const fn checked_rem(self, rhs: i16) -> Option<Self>
Calculates the remainder when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i16, 4>::new(5).unwrap();
assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i16, 4>::MIN.checked_rem(-1), None);
Sourcepub const fn checked_rem_euclid(self, rhs: i16) -> Option<Self>
pub const fn checked_rem_euclid(self, rhs: i16) -> Option<Self>
Calculates the multiplication of self
and rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i16, 4>::new(5).unwrap();
assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i16, 4>::MIN.checked_rem_euclid(-1), None);
Sourcepub const fn checked_ilog(self, base: i16) -> Option<u32>
pub const fn checked_ilog(self, base: i16) -> Option<u32>
Sourcepub const fn checked_ilog2(self) -> Option<u32>
pub const fn checked_ilog2(self) -> Option<u32>
Sourcepub const fn checked_ilog10(self) -> Option<u32>
pub const fn checked_ilog10(self) -> Option<u32>
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Shifts self
left by rhs
bits.
Returns None
if rhs
is larger than or equal to the number of bits
in self
.
§Examples
let n = BitInt::<i16, 6>::new(0x01).unwrap();
let m = BitInt::<i16, 6>::new(0x10).unwrap();
assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i16::BITS - 1).map(BitInt::get), Some(0x00));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
Sourcepub const fn checked_pow(self, exp: u32) -> Option<Self>
pub const fn checked_pow(self, exp: u32) -> Option<Self>
Source§impl<const N: u32> BitInt<i32, N>
impl<const N: u32> BitInt<i32, N>
Sourcepub const fn checked_add(self, rhs: i32) -> Option<Self>
pub const fn checked_add(self, rhs: i32) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: i32) -> Option<Self>
pub const fn checked_sub(self, rhs: i32) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: i32) -> Option<Self>
pub const fn checked_mul(self, rhs: i32) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: i32) -> Option<Self>
pub const fn checked_div(self, rhs: i32) -> Option<Self>
Calculates the divisor when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i32, 7>::new(42).unwrap();
assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i32, 7>::MIN.checked_div(-1), None);
Sourcepub const fn checked_div_euclid(self, rhs: i32) -> Option<Self>
pub const fn checked_div_euclid(self, rhs: i32) -> Option<Self>
Calculates the quotient of Euclidean division of self
by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i32, 7>::new(42).unwrap();
assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i32, 7>::MIN.checked_div_euclid(-1), None);
Sourcepub const fn checked_rem(self, rhs: i32) -> Option<Self>
pub const fn checked_rem(self, rhs: i32) -> Option<Self>
Calculates the remainder when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i32, 4>::new(5).unwrap();
assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i32, 4>::MIN.checked_rem(-1), None);
Sourcepub const fn checked_rem_euclid(self, rhs: i32) -> Option<Self>
pub const fn checked_rem_euclid(self, rhs: i32) -> Option<Self>
Calculates the multiplication of self
and rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i32, 4>::new(5).unwrap();
assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i32, 4>::MIN.checked_rem_euclid(-1), None);
Sourcepub const fn checked_ilog(self, base: i32) -> Option<u32>
pub const fn checked_ilog(self, base: i32) -> Option<u32>
Sourcepub const fn checked_ilog2(self) -> Option<u32>
pub const fn checked_ilog2(self) -> Option<u32>
Sourcepub const fn checked_ilog10(self) -> Option<u32>
pub const fn checked_ilog10(self) -> Option<u32>
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Shifts self
left by rhs
bits.
Returns None
if rhs
is larger than or equal to the number of bits
in self
.
§Examples
let n = BitInt::<i32, 6>::new(0x01).unwrap();
let m = BitInt::<i32, 6>::new(0x10).unwrap();
assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i32::BITS - 1).map(BitInt::get), Some(0x00));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
Sourcepub const fn checked_pow(self, exp: u32) -> Option<Self>
pub const fn checked_pow(self, exp: u32) -> Option<Self>
Source§impl<const N: u32> BitInt<i64, N>
impl<const N: u32> BitInt<i64, N>
Sourcepub const fn checked_add(self, rhs: i64) -> Option<Self>
pub const fn checked_add(self, rhs: i64) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: i64) -> Option<Self>
pub const fn checked_sub(self, rhs: i64) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: i64) -> Option<Self>
pub const fn checked_mul(self, rhs: i64) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: i64) -> Option<Self>
pub const fn checked_div(self, rhs: i64) -> Option<Self>
Calculates the divisor when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i64, 7>::new(42).unwrap();
assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i64, 7>::MIN.checked_div(-1), None);
Sourcepub const fn checked_div_euclid(self, rhs: i64) -> Option<Self>
pub const fn checked_div_euclid(self, rhs: i64) -> Option<Self>
Calculates the quotient of Euclidean division of self
by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i64, 7>::new(42).unwrap();
assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i64, 7>::MIN.checked_div_euclid(-1), None);
Sourcepub const fn checked_rem(self, rhs: i64) -> Option<Self>
pub const fn checked_rem(self, rhs: i64) -> Option<Self>
Calculates the remainder when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i64, 4>::new(5).unwrap();
assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i64, 4>::MIN.checked_rem(-1), None);
Sourcepub const fn checked_rem_euclid(self, rhs: i64) -> Option<Self>
pub const fn checked_rem_euclid(self, rhs: i64) -> Option<Self>
Calculates the multiplication of self
and rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i64, 4>::new(5).unwrap();
assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i64, 4>::MIN.checked_rem_euclid(-1), None);
Sourcepub const fn checked_ilog(self, base: i64) -> Option<u32>
pub const fn checked_ilog(self, base: i64) -> Option<u32>
Sourcepub const fn checked_ilog2(self) -> Option<u32>
pub const fn checked_ilog2(self) -> Option<u32>
Sourcepub const fn checked_ilog10(self) -> Option<u32>
pub const fn checked_ilog10(self) -> Option<u32>
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Shifts self
left by rhs
bits.
Returns None
if rhs
is larger than or equal to the number of bits
in self
.
§Examples
let n = BitInt::<i64, 6>::new(0x01).unwrap();
let m = BitInt::<i64, 6>::new(0x10).unwrap();
assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i64::BITS - 1).map(BitInt::get), Some(0x00));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
Sourcepub const fn checked_pow(self, exp: u32) -> Option<Self>
pub const fn checked_pow(self, exp: u32) -> Option<Self>
Source§impl<const N: u32> BitInt<i128, N>
impl<const N: u32> BitInt<i128, N>
Sourcepub const fn checked_add(self, rhs: i128) -> Option<Self>
pub const fn checked_add(self, rhs: i128) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: i128) -> Option<Self>
pub const fn checked_sub(self, rhs: i128) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: i128) -> Option<Self>
pub const fn checked_mul(self, rhs: i128) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: i128) -> Option<Self>
pub const fn checked_div(self, rhs: i128) -> Option<Self>
Calculates the divisor when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i128, 7>::new(42).unwrap();
assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i128, 7>::MIN.checked_div(-1), None);
Sourcepub const fn checked_div_euclid(self, rhs: i128) -> Option<Self>
pub const fn checked_div_euclid(self, rhs: i128) -> Option<Self>
Calculates the quotient of Euclidean division of self
by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i128, 7>::new(42).unwrap();
assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i128, 7>::MIN.checked_div_euclid(-1), None);
Sourcepub const fn checked_rem(self, rhs: i128) -> Option<Self>
pub const fn checked_rem(self, rhs: i128) -> Option<Self>
Calculates the remainder when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i128, 4>::new(5).unwrap();
assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i128, 4>::MIN.checked_rem(-1), None);
Sourcepub const fn checked_rem_euclid(self, rhs: i128) -> Option<Self>
pub const fn checked_rem_euclid(self, rhs: i128) -> Option<Self>
Calculates the multiplication of self
and rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<i128, 4>::new(5).unwrap();
assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i128, 4>::MIN.checked_rem_euclid(-1), None);
Sourcepub const fn checked_ilog(self, base: i128) -> Option<u32>
pub const fn checked_ilog(self, base: i128) -> Option<u32>
Sourcepub const fn checked_ilog2(self) -> Option<u32>
pub const fn checked_ilog2(self) -> Option<u32>
Sourcepub const fn checked_ilog10(self) -> Option<u32>
pub const fn checked_ilog10(self) -> Option<u32>
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Shifts self
left by rhs
bits.
Returns None
if rhs
is larger than or equal to the number of bits
in self
.
§Examples
let n = BitInt::<i128, 6>::new(0x01).unwrap();
let m = BitInt::<i128, 6>::new(0x10).unwrap();
assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i128::BITS - 1).map(BitInt::get), Some(0x00));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
Sourcepub const fn checked_pow(self, exp: u32) -> Option<Self>
pub const fn checked_pow(self, exp: u32) -> Option<Self>
Source§impl<const N: u32> BitInt<isize, N>
impl<const N: u32> BitInt<isize, N>
Sourcepub const fn checked_add(self, rhs: isize) -> Option<Self>
pub const fn checked_add(self, rhs: isize) -> Option<Self>
Sourcepub const fn checked_sub(self, rhs: isize) -> Option<Self>
pub const fn checked_sub(self, rhs: isize) -> Option<Self>
Sourcepub const fn checked_mul(self, rhs: isize) -> Option<Self>
pub const fn checked_mul(self, rhs: isize) -> Option<Self>
Sourcepub const fn checked_div(self, rhs: isize) -> Option<Self>
pub const fn checked_div(self, rhs: isize) -> Option<Self>
Calculates the divisor when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<isize, 7>::new(42).unwrap();
assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<isize, 7>::MIN.checked_div(-1), None);
Sourcepub const fn checked_div_euclid(self, rhs: isize) -> Option<Self>
pub const fn checked_div_euclid(self, rhs: isize) -> Option<Self>
Calculates the quotient of Euclidean division of self
by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<isize, 7>::new(42).unwrap();
assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<isize, 7>::MIN.checked_div_euclid(-1), None);
Sourcepub const fn checked_rem(self, rhs: isize) -> Option<Self>
pub const fn checked_rem(self, rhs: isize) -> Option<Self>
Calculates the remainder when self
is divided by rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<isize, 4>::new(5).unwrap();
assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<isize, 4>::MIN.checked_rem(-1), None);
Sourcepub const fn checked_rem_euclid(self, rhs: isize) -> Option<Self>
pub const fn checked_rem_euclid(self, rhs: isize) -> Option<Self>
Calculates the multiplication of self
and rhs
.
Returns None
if rhs
is 0
or the division results in overflow.
§Examples
let n = BitInt::<isize, 4>::new(5).unwrap();
assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<isize, 4>::MIN.checked_rem_euclid(-1), None);
Sourcepub const fn checked_ilog(self, base: isize) -> Option<u32>
pub const fn checked_ilog(self, base: isize) -> Option<u32>
Sourcepub const fn checked_ilog2(self) -> Option<u32>
pub const fn checked_ilog2(self) -> Option<u32>
Sourcepub const fn checked_ilog10(self) -> Option<u32>
pub const fn checked_ilog10(self) -> Option<u32>
Sourcepub const fn checked_neg(self) -> Option<Self>
pub const fn checked_neg(self) -> Option<Self>
Sourcepub const fn checked_shl(self, rhs: u32) -> Option<Self>
pub const fn checked_shl(self, rhs: u32) -> Option<Self>
Shifts self
left by rhs
bits.
Returns None
if rhs
is larger than or equal to the number of bits
in self
.
§Examples
let n = BitInt::<isize, 6>::new(0x01).unwrap();
let m = BitInt::<isize, 6>::new(0x10).unwrap();
assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(isize::BITS - 1).map(BitInt::get), Some(0x00));
Sourcepub const fn checked_shr(self, rhs: u32) -> Option<Self>
pub const fn checked_shr(self, rhs: u32) -> Option<Self>
Sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
Sourcepub const fn checked_pow(self, exp: u32) -> Option<Self>
pub const fn checked_pow(self, exp: u32) -> Option<Self>
Source§impl<const N: u32> BitInt<i8, N>
impl<const N: u32> BitInt<i8, N>
Source§impl<const N: u32> BitInt<i16, N>
impl<const N: u32> BitInt<i16, N>
Source§impl<const N: u32> BitInt<i32, N>
impl<const N: u32> BitInt<i32, N>
Source§impl<const N: u32> BitInt<i64, N>
impl<const N: u32> BitInt<i64, N>
Source§impl<const N: u32> BitInt<i128, N>
impl<const N: u32> BitInt<i128, N>
Source§impl<const N: u32> BitInt<isize, N>
impl<const N: u32> BitInt<isize, N>
Source§impl<T: Signed + PrimInt, const N: u32> BitInt<T, N>
impl<T: Signed + PrimInt, const N: u32> BitInt<T, N>
Sourcepub const unsafe fn new_unchecked(n: T) -> Self
pub const unsafe fn new_unchecked(n: T) -> Self
Creates a new BitInt
with the given signed integer value.
This method does not check whether the value is a valid N
-bit signed
integer. This results in undefined behaviour if the value is not a valid
N
-bit signed integer.
§Safety
The value must be a valid N
-bit signed integer.