Struct ibig::UBig [−][src]
pub struct UBig(_);
Expand description
Unsigned big integer.
Arbitrarily large unsigned integer.
Examples
let a = ubig!(a2a123bbb127779cccc123123ccc base 32);
let b = ubig!(0x1231abcd4134);
let c = UBig::from_str_radix("a2a123bbb127779cccc123123ccc", 32)?;
let d = UBig::from_str_radix("1231abcd4134", 16)?;
assert_eq!(a, c);
assert_eq!(b, d);
Implementations
Returns true if the n
-th bit is set.
Examples
assert_eq!(ubig!(0b10010).bit(1), true);
assert_eq!(ubig!(0b10010).bit(3), false);
assert_eq!(ubig!(0b10010).bit(100), false);
Set the n
-th bit.
Examples
let mut a = ubig!(0b100);
a.set_bit(0);
assert_eq!(a, ubig!(0b101));
a.set_bit(10);
assert_eq!(a, ubig!(0b10000000101));
Returns the number of trailing zeros in the binary representation.
In other words, it is the smallest n
such that 2 to the power of n
divides the number.
For 0, it returns None
.
Examples
assert_eq!(ubig!(17).trailing_zeros(), Some(0));
assert_eq!(ubig!(48).trailing_zeros(), Some(4));
assert_eq!(ubig!(0b101000000).trailing_zeros(), Some(6));
assert_eq!(ubig!(0).trailing_zeros(), None);
Bit length.
The length of the binary representation of the number.
For 0, the length is 0.
For non-zero numbers it is:
in_radix(2).to_string().len()
- the index of the top 1 bit plus one
- the floor of the logarithm base 2 of the number plus one.
Examples
assert_eq!(ubig!(17).bit_len(), 5);
assert_eq!(ubig!(0b101000000).bit_len(), 9);
assert_eq!(ubig!(0).bit_len(), 0);
let x = ubig!(_0x90ffff3450897234);
assert_eq!(x.bit_len(), x.in_radix(2).to_string().len());
True if the number is a power of 2.
Examples
assert_eq!(ubig!(0).is_power_of_two(), false);
assert_eq!(ubig!(8).is_power_of_two(), true);
assert_eq!(ubig!(9).is_power_of_two(), false);
Construct from little-endian bytes.
Examples
assert_eq!(UBig::from_le_bytes(&[3, 2, 1]), ubig!(0x010203));
Construct from big-endian bytes.
Examples
assert_eq!(UBig::from_be_bytes(&[1, 2, 3]), ubig!(0x010203));
Return little-endian bytes.
Examples
assert!(ubig!(0).to_le_bytes().is_empty());
assert_eq!(ubig!(0x010203).to_le_bytes(), [3, 2, 1]);
Return big-endian bytes.
Examples
assert!(ubig!(0).to_be_bytes().is_empty());
assert_eq!(ubig!(0x010203).to_be_bytes(), [1, 2, 3]);
Convert to f32.
Round to nearest, breaking ties to even last bit.
Examples
assert_eq!(ubig!(134).to_f32(), 134.0f32);
Convert a string with an optional radix prefix to UBig.
src
may contain an optional +
after the radix prefix.
Allowed prefixes: 0b
for binary, 0o
for octal, 0x
for hexadecimal.
Examples
assert_eq!(UBig::from_str_with_radix_prefix("+0o17")?, ubig!(0o17));
assert_eq!(UBig::from_str_with_radix_prefix("0x1f")?, ubig!(0x1f));
Maximum length in bits.
UBigs up to this length are supported. Creating a longer number will panic.
This does not guarantee that there is sufficient memory to store numbers up to this length. Memory allocation may fail even for smaller numbers.
The fact that this limit fits in usize
guarantees that all bit
addressing operations can be performed using usize
.
It is typically close to usize::MAX
, but the exact value is platform-dependent.
Trait Implementations
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the &=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the |=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the ^=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
type Err = ParseError
type Err = ParseError
The associated error which can be returned from parsing.
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
type FromStrRadixErr = ParseError
Convert from a string and radix (typically 2..=36
). Read more
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
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
type Sampler = UniformUBig
type Sampler = UniformUBig
The UniformSampler
implementation supporting type X
.
Performs the <<=
operation. Read more
Performs the <<=
operation. Read more
Performs the >>=
operation. Read more
Performs the >>=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
type Error = OutOfBoundsError
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
Auto Trait Implementations
impl RefUnwindSafe for UBig
impl UnwindSafe for UBig
Blanket Implementations
Mutably borrows from an owned value. Read more
Immutably borrows from an owned value. See Borrow::borrow
Read more