pub struct ApInt { /* private fields */ }
Expand description
An arbitrary precision integer with modulo arithmetics similar to machine integers.
Implementations§
Source§impl ApInt
§Constructors
impl ApInt
§Constructors
Sourcepub fn from_bit<B>(bit: B) -> ApInt
pub fn from_bit<B>(bit: B) -> ApInt
Creates a new ApInt
from the given Bit
value with a bit width of 1
.
This function is generic over types that are convertible to Bit
such as bool
.
Sourcepub fn from_i8(val: i8) -> ApInt
pub fn from_i8(val: i8) -> ApInt
Creates a new ApInt
from a given i8
value with a bit-width of 8.
Sourcepub fn from_u8(val: u8) -> ApInt
pub fn from_u8(val: u8) -> ApInt
Creates a new ApInt
from a given u8
value with a bit-width of 8.
Sourcepub fn from_i16(val: i16) -> ApInt
pub fn from_i16(val: i16) -> ApInt
Creates a new ApInt
from a given i16
value with a bit-width of 16.
Sourcepub fn from_u16(val: u16) -> ApInt
pub fn from_u16(val: u16) -> ApInt
Creates a new ApInt
from a given u16
value with a bit-width of 16.
Sourcepub fn from_i32(val: i32) -> ApInt
pub fn from_i32(val: i32) -> ApInt
Creates a new ApInt
from a given i32
value with a bit-width of 32.
Sourcepub fn from_u32(val: u32) -> ApInt
pub fn from_u32(val: u32) -> ApInt
Creates a new ApInt
from a given u32
value with a bit-width of 32.
Sourcepub fn from_i64(val: i64) -> ApInt
pub fn from_i64(val: i64) -> ApInt
Creates a new ApInt
from a given i64
value with a bit-width of 64.
Sourcepub fn from_u64(val: u64) -> ApInt
pub fn from_u64(val: u64) -> ApInt
Creates a new ApInt
from a given u64
value with a bit-width of 64.
Sourcepub fn from_i128(val: i128) -> ApInt
pub fn from_i128(val: i128) -> ApInt
Creates a new ApInt
from a given i128
value with a bit-width of 128.
Sourcepub fn from_u128(val: u128) -> ApInt
pub fn from_u128(val: u128) -> ApInt
Creates a new ApInt
from a given u128
value with a bit-width of 128.
Sourcepub fn zero(width: BitWidth) -> ApInt
pub fn zero(width: BitWidth) -> ApInt
Creates a new ApInt
with the given bit width that represents zero.
Sourcepub fn one(width: BitWidth) -> ApInt
pub fn one(width: BitWidth) -> ApInt
Creates a new ApInt
with the given bit width that represents one.
Sourcepub fn all_unset(width: BitWidth) -> ApInt
pub fn all_unset(width: BitWidth) -> ApInt
Creates a new ApInt
with the given bit width that has all bits unset.
Note: This is equal to calling ApInt::zero
with the given width
.
Sourcepub fn all_set(width: BitWidth) -> ApInt
pub fn all_set(width: BitWidth) -> ApInt
Creates a new ApInt
with the given bit width that has all bits set.
Sourcepub fn unsigned_min_value(width: BitWidth) -> ApInt
pub fn unsigned_min_value(width: BitWidth) -> ApInt
Returns the smallest unsigned ApInt
that can be represented by the given BitWidth
.
Sourcepub fn unsigned_max_value(width: BitWidth) -> ApInt
pub fn unsigned_max_value(width: BitWidth) -> ApInt
Returns the largest unsigned ApInt
that can be represented by the given BitWidth
.
Sourcepub fn signed_min_value(width: BitWidth) -> ApInt
pub fn signed_min_value(width: BitWidth) -> ApInt
Returns the smallest signed ApInt
that can be represented by the given BitWidth
.
Sourcepub fn signed_max_value(width: BitWidth) -> ApInt
pub fn signed_max_value(width: BitWidth) -> ApInt
Returns the largest signed ApInt
that can be represented by the given BitWidth
.
Source§impl ApInt
§Assignment Operations
impl ApInt
§Assignment Operations
Sourcepub fn assign(&mut self, rhs: &ApInt)
pub fn assign(&mut self, rhs: &ApInt)
Assigns rhs
to this ApInt
.
This mutates digits and may affect the bitwidth of self
which might result in an expensive operations.
After this operation rhs
and self
are equal to each other.
Sourcepub fn strict_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn strict_assign(&mut self, rhs: &ApInt) -> Result<()>
Strictly assigns rhs
to this ApInt
.
After this operation rhs
and self
are equal to each other.
Note: Strict assigns protect against mutating the bit width
of self
and thus return an error instead of executing a probably
expensive assign
operation.
§Errors
- If
rhs
andself
have unmatching bit widths.
Source§impl ApInt
§Casting: Truncation & Extension
impl ApInt
§Casting: Truncation & Extension
Sourcepub fn into_truncate<W>(self, target_width: W) -> Result<ApInt>
pub fn into_truncate<W>(self, target_width: W) -> Result<ApInt>
Sourcepub fn truncate<W>(&mut self, target_width: W) -> Result<()>
pub fn truncate<W>(&mut self, target_width: W) -> Result<()>
Tries to truncate this ApInt
inplace to the given target_width
.
§Note
- This is a no-op if
self.width()
andtarget_width
are equal. - This operation is inplace as long as
self.width()
andtarget_width
require the same amount of digits for their representation.
§Errors
- If the
target_width
is greater than the current width.
Sourcepub fn into_zero_extend<W>(self, target_width: W) -> Result<ApInt>
pub fn into_zero_extend<W>(self, target_width: W) -> Result<ApInt>
Tries to zero-extend this ApInt
inplace to the given target_width
and returns the result.
§Note
- This is useful for method chaining.
- For more details look into
zero_extend
.
§Errors
- If the
target_width
is less than the current width.
Sourcepub fn zero_extend<W>(&mut self, target_width: W) -> Result<()>
pub fn zero_extend<W>(&mut self, target_width: W) -> Result<()>
Tries to zero-extend this ApInt
inplace to the given target_width
.
§Note
- This is a no-op if
self.width()
andtarget_width
are equal. - This operation is inplace as long as
self.width()
andtarget_width
require the same amount of digits for their representation.
§Errors
- If the
target_width
is less than the current width.
Sourcepub fn into_sign_extend<W>(self, target_width: W) -> Result<ApInt>
pub fn into_sign_extend<W>(self, target_width: W) -> Result<ApInt>
Tries to sign-extend this ApInt
inplace to the given target_width
and returns the result.
§Note
- This is useful for method chaining.
- For more details look into
sign_extend
.
§Errors
- If the
target_width
is less than the current width.
Sourcepub fn sign_extend<W>(&mut self, target_width: W) -> Result<()>
pub fn sign_extend<W>(&mut self, target_width: W) -> Result<()>
Tries to sign-extend this ApInt
inplace to the given target_width
.
§Note
- This is a no-op if
self.width()
andtarget_width
are equal. - This operation is inplace as long as
self.width()
andtarget_width
require the same amount of digits for their representation.
§Errors
- If the
target_width
is less than the current width.
Sourcepub fn into_zero_resize<W>(self, target_width: W) -> ApInt
pub fn into_zero_resize<W>(self, target_width: W) -> ApInt
Zero-resizes this ApInt
to the given target_width
and returns the result.
§Note
- This is useful for method chaining.
- For more details look into
zero_resize
.
Sourcepub fn into_sign_resize<W>(self, target_width: W) -> ApInt
pub fn into_sign_resize<W>(self, target_width: W) -> ApInt
Sign-resizes this ApInt
to the given target_width
and returns the result.
§Note
- This is useful for method chaining.
- For more details look into
sign_resize
.
Sourcepub fn zero_resize<W>(&mut self, target_width: W)
pub fn zero_resize<W>(&mut self, target_width: W)
Zero-resizes the given ApInt
inplace.
§Note
This operation will forward to
truncate
iftarget_width
is less than or equal to the width of the givenApInt
zero_extend
otherwise
Sourcepub fn sign_resize<W>(&mut self, target_width: W)
pub fn sign_resize<W>(&mut self, target_width: W)
Sign-resizes the given ApInt
inplace.
§Note
This operation will forward to
truncate
iftarget_width
is less than or equal to the width of the givenApInt
sign_extend
otherwise
Source§impl ApInt
§Utility & Helper Methods
impl ApInt
§Utility & Helper Methods
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns true
if this ApInt
represents the value zero (0
).
§Note
- Zero (
0
) is also called the additive neutral element. - This operation is more efficient than comparing two instances
of
ApInt
for the same reason.
Source§impl ApInt
§Bitwise Operations
impl ApInt
§Bitwise Operations
Sourcepub fn into_bitnot(self) -> Self
pub fn into_bitnot(self) -> Self
Flips all bits of self
and returns the result.
Sourcepub fn into_checked_bitand(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_bitand(self, rhs: &ApInt) -> Result<ApInt>
Tries to bit-and assign this ApInt
inplace to rhs
and returns the result.
Note: This forwards to
checked_bitand
.
§Errors
If self
and rhs
have unmatching bit widths.
Sourcepub fn checked_bitand_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_bitand_assign(&mut self, rhs: &ApInt) -> Result<()>
Bit-and assigns all bits of this ApInt
with the bits of rhs
.
Note: This operation is inplace of self
and won’t allocate memory.
§Errors
If self
and rhs
have unmatching bit widths.
Sourcepub fn into_checked_bitor(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_bitor(self, rhs: &ApInt) -> Result<ApInt>
Tries to bit-and assign this ApInt
inplace to rhs
and returns the result.
Note: This forwards to
checked_bitor
.
§Errors
If self
and rhs
have unmatching bit widths.
Sourcepub fn checked_bitor_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_bitor_assign(&mut self, rhs: &ApInt) -> Result<()>
Bit-or assigns all bits of this ApInt
with the bits of rhs
.
Note: This operation is inplace of self
and won’t allocate memory.
§Errors
If self
and rhs
have unmatching bit widths.
Sourcepub fn into_checked_bitxor(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_bitxor(self, rhs: &ApInt) -> Result<ApInt>
Tries to bit-xor assign this ApInt
inplace to rhs
and returns the result.
Note: This forwards to
checked_bitxor
.
§Errors
If self
and rhs
have unmatching bit widths.
Source§impl ApInt
§Bitwise Access
impl ApInt
§Bitwise Access
Sourcepub fn get_bit_at<P>(&self, pos: P) -> Result<Bit>
pub fn get_bit_at<P>(&self, pos: P) -> Result<Bit>
Returns the bit at the given bit position pos
.
This returns
Bit::Set
if the bit atpos
is1
Bit::Unset
otherwise
§Errors
- If
pos
is not a valid bit position for the width of thisApInt
.
Sourcepub fn set_bit_at<P>(&mut self, pos: P) -> Result<()>
pub fn set_bit_at<P>(&mut self, pos: P) -> Result<()>
Sets the bit at the given bit position pos
to one (1
).
§Errors
- If
pos
is not a valid bit position for the width of thisApInt
.
Sourcepub fn unset_bit_at<P>(&mut self, pos: P) -> Result<()>
pub fn unset_bit_at<P>(&mut self, pos: P) -> Result<()>
Sets the bit at the given bit position pos
to zero (0
).
§Errors
- If
pos
is not a valid bit position for the width of thisApInt
.
Sourcepub fn flip_bit_at<P>(&mut self, pos: P) -> Result<()>
pub fn flip_bit_at<P>(&mut self, pos: P) -> Result<()>
Sourcepub fn is_all_set(&self) -> bool
pub fn is_all_set(&self) -> bool
Returns``trueif all bits in the
ApInt` are set.
Sourcepub fn is_all_unset(&self) -> bool
pub fn is_all_unset(&self) -> bool
Returns true
if all bits in the ApInt
are unset.
Sourcepub fn sign_bit(&self) -> Bit
pub fn sign_bit(&self) -> Bit
Returns the sign bit of this ApInt
.
Note: This is equal to the most significant bit of this ApInt
.
Sourcepub fn set_sign_bit(&mut self)
pub fn set_sign_bit(&mut self)
Sets the sign bit of this ApInt
to one (1
).
Sourcepub fn unset_sign_bit(&mut self)
pub fn unset_sign_bit(&mut self)
Sets the sign bit of this ApInt
to zero (0
).
Sourcepub fn flip_sign_bit(&mut self)
pub fn flip_sign_bit(&mut self)
Flips the sign bit of this ApInt
.
§Note
- If the sign bit was
0
it will be1
after this operation and vice versa. - Depending on the interpretation of the
ApInt
this operation changes its signedness.
Source§impl ApInt
§Bitwise utility methods.
impl ApInt
§Bitwise utility methods.
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Returns the number of ones in the binary representation of this ApInt
.
Sourcepub fn count_zeros(&self) -> usize
pub fn count_zeros(&self) -> usize
Returns the number of zeros in the binary representation of this ApInt
.
Sourcepub fn leading_zeros(&self) -> usize
pub fn leading_zeros(&self) -> usize
Returns the number of leading zeros in the binary representation of this ApInt
.
Sourcepub fn trailing_zeros(&self) -> usize
pub fn trailing_zeros(&self) -> usize
Returns the number of trailing zeros in the binary representation of this ApInt
.
Source§impl ApInt
§Comparison Operations
impl ApInt
§Comparison Operations
Sourcepub fn checked_ult(&self, rhs: &ApInt) -> Result<bool>
pub fn checked_ult(&self, rhs: &ApInt) -> Result<bool>
Sourcepub fn checked_ule(&self, rhs: &ApInt) -> Result<bool>
pub fn checked_ule(&self, rhs: &ApInt) -> Result<bool>
Sourcepub fn checked_ugt(&self, rhs: &ApInt) -> Result<bool>
pub fn checked_ugt(&self, rhs: &ApInt) -> Result<bool>
Sourcepub fn checked_uge(&self, rhs: &ApInt) -> Result<bool>
pub fn checked_uge(&self, rhs: &ApInt) -> Result<bool>
Sourcepub fn checked_slt(&self, rhs: &ApInt) -> Result<bool>
pub fn checked_slt(&self, rhs: &ApInt) -> Result<bool>
Sourcepub fn checked_sle(&self, rhs: &ApInt) -> Result<bool>
pub fn checked_sle(&self, rhs: &ApInt) -> Result<bool>
Sourcepub fn checked_sgt(&self, rhs: &ApInt) -> Result<bool>
pub fn checked_sgt(&self, rhs: &ApInt) -> Result<bool>
Source§impl ApInt
§Arithmetic Operations
impl ApInt
§Arithmetic Operations
Sourcepub fn into_negate(self) -> ApInt
pub fn into_negate(self) -> ApInt
Negates this ApInt
inplace and returns the result.
Note: This will not allocate memory.
Sourcepub fn into_checked_add(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_add(self, rhs: &ApInt) -> Result<ApInt>
Adds rhs
to self
and returns the result.
Note: This will not allocate memory.
§Errors
- If
self
andrhs
have unmatching bit widths.
Sourcepub fn checked_add_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_add_assign(&mut self, rhs: &ApInt) -> Result<()>
Add-assigns rhs
to self
inplace.
Note: This will not allocate memory.
§Errors
- If
self
andrhs
have unmatching bit widths.
Sourcepub fn into_checked_sub(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_sub(self, rhs: &ApInt) -> Result<ApInt>
Sourcepub fn checked_sub_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_sub_assign(&mut self, rhs: &ApInt) -> Result<()>
Sourcepub fn into_checked_mul(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_mul(self, rhs: &ApInt) -> Result<ApInt>
Sourcepub fn checked_mul_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_mul_assign(&mut self, rhs: &ApInt) -> Result<()>
Sourcepub fn into_checked_udiv(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_udiv(self, rhs: &ApInt) -> Result<ApInt>
Divides self
by rhs
using unsigned interpretation and returns the result.
§Note
- This operation will not allocate memory and computes inplace of
self
. - In the low-level machine abstraction signed division and unsigned division are two different operations.
§Errors
- If
self
andrhs
have unmatching bit widths.
Sourcepub fn checked_udiv_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_udiv_assign(&mut self, rhs: &ApInt) -> Result<()>
Assignes self
to the division of self
by rhs
using unsigned
interpretation of the values.
§Note
- This operation will not allocate memory and computes inplace of
self
. - In the low-level machine abstraction signed division and unsigned division are two different operations.
§Errors
- If
self
andrhs
have unmatching bit widths.
Sourcepub fn into_checked_sdiv(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_sdiv(self, rhs: &ApInt) -> Result<ApInt>
Divides self
by rhs
using signed interpretation and returns the result.
§Note
- This operation will not allocate memory and computes inplace of
self
. - In the low-level machine abstraction signed division and unsigned division are two different operations.
§Errors
- If
self
andrhs
have unmatching bit widths.
Sourcepub fn checked_sdiv_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_sdiv_assign(&mut self, rhs: &ApInt) -> Result<()>
Assignes self
to the division of self
by rhs
using signed
interpretation of the values.
§Note
- This operation will not allocate memory and computes inplace of
self
. - In the low-level machine abstraction signed division and unsigned division are two different operations.
§Errors
- If
self
andrhs
have unmatching bit widths.
Sourcepub fn into_checked_urem(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_urem(self, rhs: &ApInt) -> Result<ApInt>
Calculates the unsigned remainder of self
by rhs
and returns the result.
§Note
- This operation will not allocate memory and computes inplace of
self
. - In the low-level machine abstraction signed division and unsigned division are two different operations.
§Errors
- If
self
andrhs
have unmatching bit widths.
Sourcepub fn checked_urem_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_urem_assign(&mut self, rhs: &ApInt) -> Result<()>
Sourcepub fn into_checked_srem(self, rhs: &ApInt) -> Result<ApInt>
pub fn into_checked_srem(self, rhs: &ApInt) -> Result<ApInt>
Calculates the signed remainder of self
by rhs
and returns the result.
§Note
- This operation will not allocate memory and computes inplace of
self
. - In the low-level machine abstraction signed division and unsigned division are two different operations.
§Errors
- If
self
andrhs
have unmatching bit widths.
Sourcepub fn checked_srem_assign(&mut self, rhs: &ApInt) -> Result<()>
pub fn checked_srem_assign(&mut self, rhs: &ApInt) -> Result<()>
Source§impl ApInt
§Shift Operations
impl ApInt
§Shift Operations
Sourcepub fn checked_shl_assign<S>(&mut self, shift_amount: S) -> Result<()>where
S: Into<ShiftAmount>,
pub fn checked_shl_assign<S>(&mut self, shift_amount: S) -> Result<()>where
S: Into<ShiftAmount>,
Shift this ApInt
left by the given shift_amount
bits.
This operation is inplace and will not allocate memory.
§Errors
- If the given
shift_amount
is invalid for the bit width of thisApInt
.
Sourcepub fn into_checked_shl<S>(self, shift_amount: S) -> Result<ApInt>where
S: Into<ShiftAmount>,
pub fn into_checked_shl<S>(self, shift_amount: S) -> Result<ApInt>where
S: Into<ShiftAmount>,
Shift this ApInt
left by the given shift_amount
bits and returns the result.
This operation is inplace and will not allocate memory.
§Errors
- If the given
shift_amount
is invalid for the bit width of thisApInt
.
Sourcepub fn checked_lshr_assign<S>(&mut self, shift_amount: S) -> Result<()>where
S: Into<ShiftAmount>,
pub fn checked_lshr_assign<S>(&mut self, shift_amount: S) -> Result<()>where
S: Into<ShiftAmount>,
Logically right-shifts this ApInt
by the given shift_amount
bits.
This operation is inplace and will not allocate memory.
§Errors
- If the given
shift_amount
is invalid for the bit width of thisApInt
.
Sourcepub fn into_checked_lshr<S>(self, shift_amount: S) -> Result<ApInt>where
S: Into<ShiftAmount>,
pub fn into_checked_lshr<S>(self, shift_amount: S) -> Result<ApInt>where
S: Into<ShiftAmount>,
Logically right-shifts this ApInt
by the given shift_amount
bits
and returns the result.
This operation is inplace and will not allocate memory.
§Errors
- If the given
shift_amount
is invalid for the bit width of thisApInt
.
Sourcepub fn checked_ashr_assign<S>(&mut self, shift_amount: S) -> Result<()>where
S: Into<ShiftAmount>,
pub fn checked_ashr_assign<S>(&mut self, shift_amount: S) -> Result<()>where
S: Into<ShiftAmount>,
Sourcepub fn into_checked_ashr<S>(self, shift_amount: S) -> Result<ApInt>where
S: Into<ShiftAmount>,
pub fn into_checked_ashr<S>(self, shift_amount: S) -> Result<ApInt>where
S: Into<ShiftAmount>,
Arithmetically right-shifts this ApInt
by the given shift_amount
bits
and returns the result.
This operation is inplace and will not allocate memory.
§Note
Arithmetic shifting copies the sign bit instead of filling up with zeros.
§Errors
- If the given
shift_amount
is invalid for the bit width of thisApInt
.
Source§impl ApInt
§Deserialization
impl ApInt
§Deserialization
Sourcepub fn from_str_radix<R, S>(radix: R, input: S) -> Result<ApInt>
pub fn from_str_radix<R, S>(radix: R, input: S) -> Result<ApInt>
Parses the given input
String
with the given Radix
and returns an ApInt
with the given target_width
BitWidth
.
Note: The given input
is parsed as big-endian value. This means, the most significant bit (MSB)
is the leftst bit in the string representation provided by the user.
The string is assumed to contain no whitespace and contain only values within a subset of the
range of 0
..9
and a
..z
depending on the given radix
.
The string is assumed to have no sign as ApInt
does not handle signdness.
§Errors
- If
input
is empty. - If
input
is not a valid representation for anApInt
for the givenradix
. - If
input
has trailing zero characters (0
), e.g."0042"
instead of"42"
. - If
input
represents anApInt
value that does not fit into the giventarget_bitwidth
.
§Examples
let a = ApInt::from_str_radix(10, "42"); // ok
let b = ApInt::from_str_radix( 2, "1011011"); // ok (dec. = 91)
let c = ApInt::from_str_radix(16, "ffcc00"); // ok (dec. = 16763904)
let c = ApInt::from_str_radix(10, "256"); // Error: 256 does not fit within 8 bits!
let d = ApInt::from_str_radix( 2, "01020"); // Error: Invalid digit '2' at position 3 for given radix.
let e = ApInt::from_str_radix(16, "hello"); // Error: "hello" is not a valid ApInt representation!
Source§impl ApInt
§Serialization
impl ApInt
§Serialization
Sourcepub fn as_string_with_radix<R>(&self, radix: R) -> String
pub fn as_string_with_radix<R>(&self, radix: R) -> String
Returns a String
representation of the binary encoded ApInt
for the given Radix
.
Source§impl ApInt
§Operations to lossful cast to primitive number types.
impl ApInt
§Operations to lossful cast to primitive number types.
Sourcepub fn resize_to_bool(&self) -> bool
pub fn resize_to_bool(&self) -> bool
Resizes this ApInt
to a bool
primitive type.
Bits in this ApInt
that are not within the bounds
of the bool
are being ignored.
§Note
- Basically this returns
true
if the least significant bit of thisApInt
is1
andfalse
otherwise.
Sourcepub fn resize_to_i8(&self) -> i8
pub fn resize_to_i8(&self) -> i8
Resizes this ApInt
to a i8
primitive type.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than8
bits the value is sign extended to the target bit width. - All bits but the least significant
8
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_u8(&self) -> u8
pub fn resize_to_u8(&self) -> u8
Resizes this ApInt
to a u8
primitive type.
§Note
- All bits but the least significant
8
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_i16(&self) -> i16
pub fn resize_to_i16(&self) -> i16
Resizes this ApInt
to a i16
primitive type.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than16
bits the value is sign extended to the target bit width. - All bits but the least significant
16
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_u16(&self) -> u16
pub fn resize_to_u16(&self) -> u16
Resizes this ApInt
to a u16
primitive type.
§Note
- All bits but the least significant
16
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_i32(&self) -> i32
pub fn resize_to_i32(&self) -> i32
Resizes this ApInt
to a i32
primitive type.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than32
bits the value is sign extended to the target bit width. - All bits but the least significant
32
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_u32(&self) -> u32
pub fn resize_to_u32(&self) -> u32
Resizes this ApInt
to a u32
primitive type.
§Note
- All bits but the least significant
32
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_i64(&self) -> i64
pub fn resize_to_i64(&self) -> i64
Resizes this ApInt
to a i64
primitive type.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than64
bits the value is sign extended to the target bit width. - All bits but the least significant
64
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_u64(&self) -> u64
pub fn resize_to_u64(&self) -> u64
Resizes this ApInt
to a u64
primitive type.
§Note
- All bits but the least significant
64
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_i128(&self) -> i128
pub fn resize_to_i128(&self) -> i128
Resizes this ApInt
to a i128
primitive type.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than128
bits the value is sign extended to the target bit width. - All bits but the least significant
128
bits are being ignored by this operation to construct the result.
Sourcepub fn resize_to_u128(&self) -> u128
pub fn resize_to_u128(&self) -> u128
Resizes this ApInt
to a u128
primitive type.
§Note
- All bits but the least significant
128
bits are being ignored by this operation to construct the result.
Source§impl ApInt
§Operations to lossless cast to primitive number types.
impl ApInt
§Operations to lossless cast to primitive number types.
Sourcepub fn try_to_bool(&self) -> Result<bool>
pub fn try_to_bool(&self) -> Result<bool>
Sourcepub fn try_to_i8(&self) -> Result<i8>
pub fn try_to_i8(&self) -> Result<i8>
Tries to represent the value of this ApInt
as a i8
.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than8
bits the value is sign extended to the target bit width. - This conversion is possible as long as the value represented
by this
ApInt
does not exceed the maximum value ofu8
.
§Errors
- If the value represented by this
ApInt
can not be represented by ai8
.
Sourcepub fn try_to_i16(&self) -> Result<i16>
pub fn try_to_i16(&self) -> Result<i16>
Tries to represent the value of this ApInt
as a i16
.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than16
bits the value is sign extended to the target bit width. - This conversion is possible as long as the value represented
by this
ApInt
does not exceed the maximum value ofu16
.
§Errors
- If the value represented by this
ApInt
can not be represented by ai16
.
Sourcepub fn try_to_u16(&self) -> Result<u16>
pub fn try_to_u16(&self) -> Result<u16>
Sourcepub fn try_to_i32(&self) -> Result<i32>
pub fn try_to_i32(&self) -> Result<i32>
Tries to represent the value of this ApInt
as a i32
.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than32
bits the value is sign extended to the target bit width. - This conversion is possible as long as the value represented
by this
ApInt
does not exceed the maximum value ofu32
.
§Errors
- If the value represented by this
ApInt
can not be represented by ai32
.
Sourcepub fn try_to_u32(&self) -> Result<u32>
pub fn try_to_u32(&self) -> Result<u32>
Sourcepub fn try_to_i64(&self) -> Result<i64>
pub fn try_to_i64(&self) -> Result<i64>
Tries to represent the value of this ApInt
as a i64
.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than64
bits the value is sign extended to the target bit width. - This conversion is possible as long as the value represented
by this
ApInt
does not exceed the maximum value ofu64
.
§Errors
- If the value represented by this
ApInt
can not be represented by ai64
.
Sourcepub fn try_to_u64(&self) -> Result<u64>
pub fn try_to_u64(&self) -> Result<u64>
Sourcepub fn try_to_i128(&self) -> Result<i128>
pub fn try_to_i128(&self) -> Result<i128>
Tries to represent the value of this ApInt
as a i128
.
§Note
- This operation will conserve the signedness of the
value. This means that for
ApInt
instances with aBitWidth
less than128
bits the value is sign extended to the target bit width. - This conversion is possible as long as the value represented
by this
ApInt
does not exceed the maximum value ofu128
.
§Errors
- If the value represented by this
ApInt
can not be represented by ai128
.
Sourcepub fn try_to_u128(&self) -> Result<u128>
pub fn try_to_u128(&self) -> Result<u128>
Tries to represent the value of this ApInt
as a u128
.
§Note
- This conversion is possible as long as the value represented
by this
ApInt
does not exceed the maximum value ofu128
.
§Complexity
- 𝒪(n) where n is the number of digits of this
ApInt
.
§Errors
- If the value represented by this
ApInt
can not be represented by au128
.
Source§impl ApInt
§Random Utilities using rand
crate.
impl ApInt
§Random Utilities using rand
crate.
Sourcepub fn random_with_width(width: BitWidth) -> ApInt
pub fn random_with_width(width: BitWidth) -> ApInt
Creates a new ApInt
with the given BitWidth
and random Digit
s.
Sourcepub fn random_with_width_using<R>(width: BitWidth, rng: &mut R) -> ApIntwhere
R: Rng,
pub fn random_with_width_using<R>(width: BitWidth, rng: &mut R) -> ApIntwhere
R: Rng,
Creates a new ApInt
with the given BitWidth
and random Digit
s
using the given random number generator.
Note: This is useful for cryptographic or testing purposes.
Sourcepub fn randomize(&mut self)
pub fn randomize(&mut self)
Randomizes the digits of this ApInt
inplace.
This won’t change its BitWidth
.
Sourcepub fn randomize_using<R>(&mut self, rng: &mut R)where
R: Rng,
pub fn randomize_using<R>(&mut self, rng: &mut R)where
R: Rng,
Randomizes the digits of this ApInt
inplace using the given
random number generator.
This won’t change its BitWidth
.
Trait Implementations§
Source§impl<'a> AddAssign<&'a ApInt> for ApInt
impl<'a> AddAssign<&'a ApInt> for ApInt
Source§fn add_assign(&mut self, rhs: &'a ApInt)
fn add_assign(&mut self, rhs: &'a ApInt)
+=
operation. Read moreSource§impl<'a> BitAndAssign<&'a ApInt> for ApInt
impl<'a> BitAndAssign<&'a ApInt> for ApInt
Source§fn bitand_assign(&mut self, rhs: &'a ApInt)
fn bitand_assign(&mut self, rhs: &'a ApInt)
&=
operation. Read moreSource§impl<'a> BitOrAssign<&'a ApInt> for ApInt
impl<'a> BitOrAssign<&'a ApInt> for ApInt
Source§fn bitor_assign(&mut self, rhs: &'a ApInt)
fn bitor_assign(&mut self, rhs: &'a ApInt)
|=
operation. Read moreSource§impl<'a> BitXorAssign<&'a ApInt> for ApInt
impl<'a> BitXorAssign<&'a ApInt> for ApInt
Source§fn bitxor_assign(&mut self, rhs: &'a ApInt)
fn bitxor_assign(&mut self, rhs: &'a ApInt)
^=
operation. Read moreSource§impl<'de> Deserialize<'de> for ApInt
impl<'de> Deserialize<'de> for ApInt
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'a> MulAssign<&'a ApInt> for ApInt
impl<'a> MulAssign<&'a ApInt> for ApInt
Source§fn mul_assign(&mut self, rhs: &'a ApInt)
fn mul_assign(&mut self, rhs: &'a ApInt)
*=
operation. Read moreSource§impl<'a> SubAssign<&'a ApInt> for ApInt
impl<'a> SubAssign<&'a ApInt> for ApInt
Source§fn sub_assign(&mut self, rhs: &'a ApInt)
fn sub_assign(&mut self, rhs: &'a ApInt)
-=
operation. Read moreimpl Eq for ApInt
impl Send for ApInt
ApInt
is safe to send between threads since it does not own
aliasing memory and has no reference counting mechanism like Rc
.
impl Sync for ApInt
ApInt
is safe to share between threads since it does not own
aliasing memory and has no mutable internal state like Cell
or RefCell
.