Struct apint::Int[][src]

pub struct Int { /* fields omitted */ }

Signed machine integer with arbitrary bitwidths and modulo arithmetics.

Thin convenience wrapper around ApInt for static signed interpretation of the value.

This very cheaply transformes to and from ApInt and UInt instances and together with UInt offers a more elegant and higher-level abstraction interface to the lower-level ApInt.

Methods

impl Int
[src]

Transforms this Int into an equivalent ApInt instance.

Transforms this Int into an equivalent UInt instance.

impl Int
[src]

Creates a new Int 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.

Creates a new Int from a given i8 value with a bit-width of 8.

Creates a new Int from a given i16 value with a bit-width of 16.

Creates a new Int from a given i32 value with a bit-width of 32.

Creates a new Int from a given i64 value with a bit-width of 64.

Creates a new Int from a given i64 value with a bit-width of 64.

Creates a new Int with the given bit width that represents zero.

Creates a new Int with the given bit width that represents one.

Creates a new Int with the given bit width that has all bits unset.

Note: This is equal to calling Int::zero with the given width.

Creates a new Int with the given bit width that has all bits set.

Note

  • This is equal to minus one on any twos-complement machine.

Returns the smallest Int that can be represented by the given BitWidth.

Returns the largest Int that can be represented by the given BitWidth.

impl Int
[src]

Returns true if this Int 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 Int for the same reason.

Returns true if this Int represents the value one (1).

Note

  • One (1) is also called the multiplicative neutral element.
  • This operation is more efficient than comparing two instances of Int for the same reason.

Returns true if this Int represents an even number.

Returns true if this Int represents an odd number.

Returns true if the value of this Int is positive.

Returns true if the value of this Int is negative.

Returns a number representing sign of this ApInt.

  • 0 if the number is zero
  • 1 if the number is positive
  • -1 if the number is negative

Returns an absolute value representation of this Int.

Note

  • Consumes self.
  • Does nothing for positive Int instances.

Converts this Int into its absolute value representation.

  • Does nothing for positive Int instances.

impl Int
[src]

Less-than (lt) comparison between self and rhs.

Note

  • Returns Ok(true) if self < rhs.
  • Interprets both Int instances as unsigned values.

Errors

  • If self and rhs have unmatching bit widths.

Less-equals (le) comparison between self and rhs.

Note

  • Returns Ok(true) if self <= rhs.
  • Interprets both Int instances as unsigned values.

Errors

  • If self and rhs have unmatching bit widths.

Greater-than (gt) comparison between self and rhs.

Note

  • Returns Ok(true) if self > rhs.
  • Interprets both Int instances as unsigned values.

Errors

  • If self and rhs have unmatching bit widths.

Greater-equals (ge) comparison between self and rhs.

Note

  • Returns Ok(true) if self >= rhs.
  • Interprets both Int instances as unsigned values.

Errors

  • If self and rhs have unmatching bit widths.

impl Int
[src]

Resizes this Int to a bool primitive type.

Bits in this Int that are not within the bounds of the bool are being ignored.

Note

  • Basically this returns true if the least significant bit of this Int is 1 and false otherwise.

Resizes this Int to a i8 primitive type.

Note

  • All bits but the least significant 8 bits are being ignored by this operation to construct the result.

Resizes this Int to a i16 primitive type.

Note

  • All bits but the least significant 16 bits are being ignored by this operation to construct the result.

Resizes this Int to a i32 primitive type.

Note

  • All bits but the least significant 32 bits are being ignored by this operation to construct the result.

Resizes this Int to a i64 primitive type.

Note

  • All bits but the least significant 64 bits are being ignored by this operation to construct the result.

Resizes this Int to a i128 primitive type.

Note

  • All bits but the least significant 128 bits are being ignored by this operation to construct the result.

impl Int
[src]

Tries to represent the value of this Int as a bool.

Note

This returns true if the value represented by this Int is 1, returns false if the value represented by this Int is 0 and returns an error otherwise.

Errors

  • If the value represented by this Int can not be represented by a bool.

Tries to represent the value of this Int as a i8.

Note

  • This conversion is possible as long as the value represented by this Int does not exceed the maximum value of i8.

Errors

  • If the value represented by this Int can not be represented by a u8.

Tries to represent the value of this Int as a i16.

Note

  • This conversion is possible as long as the value represented by this Int does not exceed the maximum value of i16.

Errors

  • If the value represented by this Int can not be represented by a i16.

Tries to represent the value of this Int as a i32.

Note

  • This conversion is possible as long as the value represented by this Int does not exceed the maximum value of i32.

Errors

  • If the value represented by this Int can not be represented by a i32.

Tries to represent the value of this Int as a i64.

Note

  • This conversion is possible as long as the value represented by this Int does not exceed the maximum value of i64.

Errors

  • If the value represented by this Int can not be represented by a i64.

Tries to represent the value of this Int as a i128.

Note

  • This conversion is possible as long as the value represented by this Int does not exceed the maximum value of i128.

Complexity

  • 𝒪(n) where n is the number of digits of this Int.

Errors

  • If the value represented by this Int can not be represented by a i128.

impl Int
[src]

Shift this Int 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 this Int.

Shift this Int 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 this Int.

Right-shifts this Int 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 this Int.

Right-shifts this Int 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 this Int.

impl Int
[src]

Creates a new Int with the given BitWidth and random Digits.

Creates a new Int with the given BitWidth and random Digits using the given random number generator.

Note: This is useful for cryptographic or testing purposes.

Randomizes the digits of this Int inplace.

This won't change its BitWidth.

Randomizes the digits of this Int inplace using the given random number generator.

This won't change its BitWidth.

impl Int
[src]

Assigns rhs to this Int.

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.

Strictly assigns rhs to this Int.

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 and self have unmatching bit widths.

impl Int
[src]

Tries to truncate this Int inplace to the given target_width and returns the result.

Note

  • This is useful for method chaining.
  • For more details look into truncate.

Errors

  • If the target_width is greater than the current width.

Tries to truncate this Int inplace to the given target_width.

Note

  • This is a no-op if self.width() and target_width are equal.
  • This operation is inplace as long as self.width() and target_width require the same amount of digits for their representation.

Errors

  • If the target_width is greater than the current width.

Tries to zero-extend this Int inplace to the given target_width and returns the result.

Note

  • This is useful for method chaining.
  • For more details look into extend.

Errors

  • If the target_width is less than the current width.

Tries to extend this Int inplace to the given target_width.

Note

  • This is a no-op if self.width() and target_width are equal.
  • This operation is inplace as long as self.width() and target_width require the same amount of digits for their representation.

Errors

  • If the target_width is less than the current width.

Resizes this Int to the given target_width and returns the result.

Note

  • This is useful for method chaining.
  • For more details look into resize.

Resizes the given Int inplace.

Note

This operation will forward to

  • truncate if target_width is less than or equal to the width of the given Int
  • extend otherwise

impl Int
[src]

Flips all bits of self and returns the result.

Flip all bits of this Int inplace.

Tries to bit-and assign this Int inplace to rhs and returns the result.

Note: This forwards to checked_bitand.

Errors

If self and rhs have unmatching bit widths.

Bit-and assigns all bits of this Int 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.

Tries to bit-and assign this Int inplace to rhs and returns the result.

Note: This forwards to checked_bitor.

Errors

If self and rhs have unmatching bit widths.

Bit-or assigns all bits of this Int 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.

Tries to bit-xor assign this Int inplace to rhs and returns the result.

Note: This forwards to checked_bitxor.

Errors

If self and rhs have unmatching bit widths.

Bit-xor assigns all bits of this Int 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.

impl Int
[src]

Returns the bit at the given bit position pos.

This returns

  • Bit::Set if the bit at pos is 1
  • Bit::Unset otherwise

Errors

  • If pos is not a valid bit position for the width of this Int.

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 this Int.

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 this Int.

Flips the bit at the given bit position pos.

Note

  • If the bit at the given position was 0 it will be 1 after this operation and vice versa.

Errors

  • If pos is not a valid bit position for the width of this Int.

Sets all bits of this Int to one (1).

Returns true if all bits in this Int are set.

Sets all bits of this Int to zero (0).

Returns true if all bits in this Int are unset.

Flips all bits of this Int.

Returns the sign bit of this Int.

Note: This is equal to the most significant bit of this Int.

Sets the sign bit of this Int to one (1).

Sets the sign bit of this Int to zero (0).

Flips the sign bit of this Int.

Note

  • If the sign bit was 0 it will be 1 after this operation and vice versa.
  • Depending on the interpretation of the Int this operation changes its signedness.

impl Int
[src]

Returns the number of ones in the binary representation of this Int.

Returns the number of zeros in the binary representation of this Int.

Returns the number of leading zeros in the binary representation of this Int.

Returns the number of trailing zeros in the binary representation of this Int.

impl Int
[src]

Negates this Int inplace and returns the result.

Note: This will not allocate memory.

Negates this Int inplace.

Note: This will not allocate memory.

Adds rhs to self and returns the result.

Note: This will not allocate memory.

Errors

  • If self and rhs have unmatching bit widths.

Add-assigns rhs to self inplace.

Note: This will not allocate memory.

Errors

  • If self and rhs have unmatching bit widths.

Subtracts rhs from self and returns the result.

Note

In the low-level bit-wise representation there is no difference between signed and unsigned subtraction of fixed bit-width integers. (Cite: LLVM)

Errors

  • If self and rhs have unmatching bit widths.

Subtract-assigns rhs from self inplace.

Note

In the low-level bit-wise representation there is no difference between signed and unsigned subtraction of fixed bit-width integers. (Cite: LLVM)

Errors

  • If self and rhs have unmatching bit widths.

Subtracts rhs from self and returns the result.

Note

In the low-level bit-wise representation there is no difference between signed and unsigned multiplication of fixed bit-width integers. (Cite: LLVM)

Errors

  • If self and rhs have unmatching bit widths.

Multiply-assigns rhs to self inplace.

Note

In the low-level bit-wise representation there is no difference between signed and unsigned multiplication of fixed bit-width integers. (Cite: LLVM)

Errors

  • If self and rhs have unmatching bit widths.

Divides 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 and rhs have unmatching bit widths.

Assignes self to the division of self by rhs.

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 and rhs have unmatching bit widths.

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 and rhs have unmatching bit widths.

Assignes self to the unsigned remainder of self by rhs.

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 and rhs have unmatching bit widths.

Trait Implementations

impl Debug for Int
[src]

Formats the value using the given formatter. Read more

impl Clone for Int
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Int
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for Int
[src]

impl Hash for Int
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl From<ApInt> for Int
[src]

Performs the conversion.

impl<B> From<B> for Int where
    B: Into<Bit>, 
[src]

Performs the conversion.

impl From<i8> for Int
[src]

Performs the conversion.

impl From<i16> for Int
[src]

Performs the conversion.

impl From<i32> for Int
[src]

Performs the conversion.

impl From<i64> for Int
[src]

Performs the conversion.

impl From<i128> for Int
[src]

Performs the conversion.

impl From<[i64; 2]> for Int
[src]

Performs the conversion.

impl From<[i64; 3]> for Int
[src]

Performs the conversion.

impl From<[i64; 4]> for Int
[src]

Performs the conversion.

impl From<[i64; 5]> for Int
[src]

Performs the conversion.

impl From<[i64; 6]> for Int
[src]

Performs the conversion.

impl From<[i64; 7]> for Int
[src]

Performs the conversion.

impl From<[i64; 8]> for Int
[src]

Performs the conversion.

impl From<[i64; 16]> for Int
[src]

Performs the conversion.

impl From<[i64; 32]> for Int
[src]

Performs the conversion.

impl PartialOrd for Int
[src]

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<S> Shl<S> for Int where
    S: Into<ShiftAmount>, 
[src]

The resulting type after applying the << operator.

Performs the << operation.

impl<S> Shr<S> for Int where
    S: Into<ShiftAmount>, 
[src]

The resulting type after applying the >> operator.

Performs the >> operation.

impl<S> ShlAssign<S> for Int where
    S: Into<ShiftAmount>, 
[src]

Performs the <<= operation.

impl<S> ShrAssign<S> for Int where
    S: Into<ShiftAmount>, 
[src]

Performs the >>= operation.

impl Not for Int
[src]

The resulting type after applying the ! operator.

Performs the unary ! operation.

impl<'a> BitAnd<&'a Int> for Int
[src]

The resulting type after applying the & operator.

Performs the & operation.

impl<'a, 'b> BitAnd<&'a Int> for &'b Int
[src]

The resulting type after applying the & operator.

Performs the & operation.

impl<'a, 'b> BitAnd<&'a Int> for &'b mut Int
[src]

The resulting type after applying the & operator.

Performs the & operation.

impl<'a> BitOr<&'a Int> for Int
[src]

The resulting type after applying the | operator.

Performs the | operation.

impl<'a, 'b> BitOr<&'a Int> for &'b Int
[src]

The resulting type after applying the | operator.

Performs the | operation.

impl<'a, 'b> BitOr<&'a Int> for &'b mut Int
[src]

The resulting type after applying the | operator.

Performs the | operation.

impl<'a> BitXor<&'a Int> for Int
[src]

The resulting type after applying the ^ operator.

Performs the ^ operation.

impl<'a, 'b> BitXor<&'a Int> for &'b Int
[src]

The resulting type after applying the ^ operator.

Performs the ^ operation.

impl<'a, 'b> BitXor<&'a Int> for &'b mut Int
[src]

The resulting type after applying the ^ operator.

Performs the ^ operation.

impl<'a> BitAndAssign<&'a Int> for Int
[src]

Performs the &= operation.

impl<'a> BitOrAssign<&'a Int> for Int
[src]

Performs the |= operation.

impl<'a> BitXorAssign<&'a Int> for Int
[src]

Performs the ^= operation.

impl Neg for Int
[src]

The resulting type after applying the - operator.

Performs the unary - operation.

impl<'a> Neg for &'a Int
[src]

The resulting type after applying the - operator.

Performs the unary - operation.

impl<'a> Neg for &'a mut Int
[src]

The resulting type after applying the - operator.

Performs the unary - operation.

impl<'a> Add<&'a Int> for Int
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<'a, 'b> Add<&'a Int> for &'b Int
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<'a> AddAssign<&'a Int> for Int
[src]

Performs the += operation.

impl<'a> Sub<&'a Int> for Int
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a, 'b> Sub<&'a Int> for &'b Int
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a> SubAssign<&'a Int> for Int
[src]

Performs the -= operation.

impl<'a> Mul<&'a Int> for Int
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<'a, 'b> Mul<&'a Int> for &'b Int
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<'a> MulAssign<&'a Int> for Int
[src]

Performs the *= operation.

impl<'a> Div<&'a Int> for Int
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, 'b> Div<&'a Int> for &'b Int
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a> DivAssign<&'a Int> for Int
[src]

Performs the /= operation.

impl<'a> Rem<&'a Int> for Int
[src]

The resulting type after applying the % operator.

Performs the % operation.

impl<'a, 'b> Rem<&'a Int> for &'b Int
[src]

The resulting type after applying the % operator.

Performs the % operation.

impl<'a> RemAssign<&'a Int> for Int
[src]

Performs the %= operation.

impl Binary for Int
[src]

Formats the value using the given formatter.

impl Octal for Int
[src]

Formats the value using the given formatter.

impl LowerHex for Int
[src]

Formats the value using the given formatter.

impl UpperHex for Int
[src]

Formats the value using the given formatter.

Auto Trait Implementations

impl Send for Int

impl Sync for Int