[][src]Struct ibig::IBig

pub struct IBig { /* fields omitted */ }

Signed big integer.

Arbitrarily large signed integer.

Examples

let a = ibig!(a2a123bbb127779cccc123123ccc base 32);
let b = ibig!(-0x1231abcd4134);
let c = IBig::from_str_radix("a2a123bbb127779cccc123123ccc", 32)?;
let d = IBig::from_str_radix("-1231abcd4134", 16)?;
assert_eq!(a, c);
assert_eq!(b, d);
Ok::<(), ParseError>(())

Implementations

impl IBig[src]

pub fn trailing_zeros(&self) -> Option<usize>[src]

Returns the number of trailing zeros in the two's complement 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!(ibig!(17).trailing_zeros(), Some(0));
assert_eq!(ibig!(-48).trailing_zeros(), Some(4));
assert_eq!(ibig!(-0b101000000).trailing_zeros(), Some(6));
assert_eq!(ibig!(0).trailing_zeros(), None);

impl IBig[src]

pub fn in_radix(&self, radix: u32) -> InRadix<'_>[src]

Representation in a given radix.

Panics

Panics radix is not between 2 and 36 inclusive.

Examples

assert_eq!(format!("{}", ibig!(100).in_radix(2)), "1100100");
assert_eq!(format!("{}", ibig!(-3000).in_radix(16)), "-bb8");
assert_eq!(format!("{:#}", ibig!(3000).in_radix(16)), "BB8");
assert_eq!(format!("{:+010}", ibig!(100).in_radix(2)), "+001100100");
assert_eq!(format!("{:=^10}", ibig!(-100).in_radix(2)), "=-1100100=");
// For bases 2, 8, 10, 16 we don't have to use `in_radix`:
assert_eq!(format!("{:x}", ibig!(-3000)), "-bb8");

pub fn to_str_radix(&self, radix: u32) -> String[src]

String representation in an arbitrary radix.

Equivalent to self.to_radix(radix).to_string() but more efficient.

Panics

Panics radix is not between 2 and 36 inclusive.

Examples

assert_eq!(ibig!(-0x123f).to_str_radix(16), "-123f");

pub fn to_str_radix_uppercase(&self, radix: u32) -> String[src]

Upper-case string representation in an arbitrary radix.

Equivalent to format!("{:#}", self.in_radix(radix)) but more efficient.

Panics

Panics radix is not between 2 and 36 inclusive.

Examples

assert_eq!(ibig!(-0x123f).to_str_radix_uppercase(16), "-123F");

impl IBig[src]

pub fn is_negative(&self) -> bool[src]

Is the number smaller than 0?

Examples

assert_eq!(ibig!(-5).is_negative(), true);
assert_eq!(ibig!(0).is_negative(), false);
assert_eq!(ibig!(5).is_negative(), false);

pub fn is_positive(&self) -> bool[src]

Is the number greater than 0?

Examples

assert_eq!(ibig!(-5).is_positive(), false);
assert_eq!(ibig!(0).is_positive(), false);
assert_eq!(ibig!(5).is_positive(), true);

impl IBig[src]

pub fn from_str_radix(src: &str, radix: u32) -> Result<IBig, ParseError>[src]

Convert a string in a given base to IBig.

The string may contain a + or - prefix. Digits 10-35 are represented by a-z or A-Z.

Panics

Panics if radix not in range 2-36.

Examples

assert_eq!(IBig::from_str_radix("-7ab", 32)?, ibig!(-7499));

pub fn from_str_with_radix_prefix(src: &str) -> Result<IBig, ParseError>[src]

Convert a string with an optional radix prefix to IBig.

src may contain an '+' or - prefix..

Allowed prefixes: 0b for binary, 0o for octal, 0x for hexadecimal.

Examples

assert_eq!(IBig::from_str_with_radix_prefix("+0o17")?, ibig!(0o17));
assert_eq!(IBig::from_str_with_radix_prefix("-0x1f")?, ibig!(-0x1f));

Trait Implementations

impl Binary for IBig[src]

impl Debug for IBig[src]

impl Eq for IBig[src]

impl<'_> From<&'_ UBig> for IBig[src]

impl From<UBig> for IBig[src]

impl From<i128> for IBig[src]

impl From<i16> for IBig[src]

impl From<i32> for IBig[src]

impl From<i64> for IBig[src]

impl From<i8> for IBig[src]

impl From<isize> for IBig[src]

impl From<u128> for IBig[src]

impl From<u16> for IBig[src]

impl From<u32> for IBig[src]

impl From<u64> for IBig[src]

impl From<u8> for IBig[src]

impl From<usize> for IBig[src]

impl LowerHex for IBig[src]

impl Neg for IBig[src]

type Output = IBig

The resulting type after applying the - operator.

impl<'_> Neg for &'_ IBig[src]

type Output = IBig

The resulting type after applying the - operator.

impl Octal for IBig[src]

impl PartialEq<IBig> for IBig[src]

impl StructuralEq for IBig[src]

impl StructuralPartialEq for IBig[src]

impl<'_> TryFrom<&'_ IBig> for u8[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for u16[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for i128[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for isize[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for UBig[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for u32[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for u64[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for u128[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for usize[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for i8[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for i16[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for i32[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ IBig> for i64[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for u8[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for u16[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for i128[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for isize[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for UBig[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for u32[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for u64[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for u128[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for usize[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for i8[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for i16[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for i32[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl TryFrom<IBig> for i64[src]

type Error = OutOfBoundsError

The type returned in the event of a conversion error.

impl UpperHex for IBig[src]

Auto Trait Implementations

impl RefUnwindSafe for IBig

impl Send for IBig

impl Sync for IBig

impl Unpin for IBig

impl UnwindSafe for IBig

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.