Struct BigInt

Source
pub struct BigInt { /* private fields */ }

Implementations§

Source§

impl BigInt

Source

pub fn add_bi(&self, other: &BigInt) -> Self

Source

pub fn add_bi_mut(&mut self, other: &BigInt)

Source

pub fn add_i32(&self, other: i32) -> Self

Source

pub fn add_i32_mut(&mut self, other: i32)

Source§

impl BigInt

Source

pub fn div_bi(&self, other: &BigInt) -> Self

Source

pub fn div_bi_mut(&mut self, other: &BigInt)

Source

pub fn div_i32(&self, other: i32) -> Self

Source

pub fn div_i32_mut(&mut self, other: i32)

Source§

impl BigInt

Source

pub fn mul_bi(&self, other: &BigInt) -> Self

Source

pub fn mul_bi_mut(&mut self, other: &BigInt)

Source

pub fn mul_i32(&self, other: i32) -> Self

Source

pub fn mul_i32_mut(&mut self, other: i32)

Source

pub fn mul_pow2(&self, exp: u32) -> Self

returns self * 2^exp

Source

pub fn mul_pow2_mut(&mut self, exp: u32)

self *= 2^exp

Source§

impl BigInt

Source

pub fn pow_u32(&self, exp: u32) -> Self

0^0 is 1

Source

pub fn pow_u32_mut(&mut self, exp: u32)

Source

pub fn pow2(exp: u32) -> Self

returns 2^exp

Source§

impl BigInt

Source

pub fn rem_bi(&self, other: &BigInt) -> Self

Source

pub fn rem_bi_mut(&mut self, other: &BigInt)

Source

pub fn rem_i32(&self, other: i32) -> Self

Source

pub fn rem_i32_mut(&mut self, other: i32)

Source

pub fn rem_pow2(&self, other: i32) -> Self

other must be a power of 2

Source§

impl BigInt

Source

pub fn sub_bi(&self, other: &BigInt) -> Self

Source

pub fn sub_bi_mut(&mut self, other: &BigInt)

Source

pub fn sub_i32(&self, other: i32) -> Self

Source

pub fn sub_i32_mut(&mut self, other: i32)

Source§

impl BigInt

Source

pub fn lt_bi(&self, other: &BigInt) -> bool

self < other

Source

pub fn gt_bi(&self, other: &BigInt) -> bool

self > other

Source

pub fn eq_bi(&self, other: &BigInt) -> bool

Though PartialEq is implemented for BigInt, this method exists. That’s for consistency.

Source

pub fn neq_bi(&self, other: &BigInt) -> bool

Source

pub fn leq_bi(&self, other: &BigInt) -> bool

self <= other

Source

pub fn geq_bi(&self, other: &BigInt) -> bool

self >= other

Source

pub fn comp_bi(&self, other: &BigInt) -> Ordering

Source

pub fn lt_i32(&self, other: i32) -> bool

self < other

Source

pub fn gt_i32(&self, other: i32) -> bool

self > other

Source

pub fn eq_i32(&self, other: i32) -> bool

Source

pub fn neq_i32(&self, other: i32) -> bool

Source

pub fn leq_i32(&self, other: i32) -> bool

self <= other

Source

pub fn geq_i32(&self, other: i32) -> bool

self >= other

Source

pub fn comp_i32(&self, other: i32) -> Ordering

Source§

impl BigInt

Source

pub fn from_i32(n: i32) -> Self

Source

pub fn to_i32(&self) -> Result<i32, ConversionError>

Source

pub fn from_i64(n: i64) -> Self

Source

pub fn to_i64(&self) -> Result<i64, ConversionError>

Source

pub fn from_i128(n: i128) -> Self

Source

pub fn to_i128(&self) -> Result<i128, ConversionError>

Source

pub fn from_ubi(n: UBigInt, is_neg: bool) -> Self

Source

pub fn to_ubi(&self) -> Result<UBigInt, ConversionError>

Source

pub fn from_string(s: &str) -> Result<Self, ConversionError>

('-')? UBigInt
see UBigInt::from_string

Source

pub fn to_scientific_notation(&self, digits_max_len: usize) -> String

‘9.8e5’

Source

pub fn to_string_dec(&self) -> String

see UBigInt::to_string_dec

Source

pub fn to_string_hex(&self, prefix: bool) -> String

see UBigInt::to_string_hex

Source

pub fn to_string_oct(&self, prefix: bool) -> String

see UBigInt::to_string_oct

Source

pub fn to_string_bin(&self, prefix: bool) -> String

see UBigInt::to_string_bin

Source§

impl BigInt

Source

pub fn exp2(n: u64) -> Self

It returns 2^n

Source

pub fn log2(&self) -> Self

It returns 0 when self is 0. It returns log2(abs(self)).

Source

pub fn log2_accurate(&self) -> Self

It returns truncate(log2(abs(self)) * 4294967296). It returns 0 when self is 0.

Source

pub fn sqrt(&self) -> Self

It returns (sign * sqrt(abs(self)))

Source

pub fn neg(&self) -> Self

Source

pub fn neg_mut(&mut self)

Source

pub fn abs(&self) -> Self

Source

pub fn abs_mut(&mut self)

Source

pub fn is_prime(&self) -> bool

Sign of self doesn’t make any difference

Source

pub fn prime_factorial(&self) -> Vec<Self>

Sign of self doesn’t make any difference

Source

pub fn factorial(n: u32) -> Self

Source

pub fn fibonacci(n: u32) -> Self

Source

pub fn shift_right(&self, n: usize) -> Self

divide by 2^32

Source

pub fn shift_right_mut(&mut self, n: usize)

divide by 2^32

Source

pub fn shift_left(&self, n: usize) -> Self

multiply 2^32

Source

pub fn shift_left_mut(&mut self, n: usize)

multiply 2^32

Source

pub fn slice_right(&self, n: usize) -> Self

modulo 2^32 (it doesn’t care about sign)
It panics when n is too big. It returns 0 when n is 0.

Source

pub fn slice_right_mut(&mut self, n: usize)

modulo 2^32 (it doesn’t care about sign)
It panics when n is too big. It makes self 0 when n is 0.

Source§

impl BigInt

Source

pub fn len(&self) -> usize

size of its internal vector

Source

pub fn zero() -> Self

Source

pub fn one() -> Self

Source

pub fn is_zero(&self) -> bool

Source

pub fn is_one(&self) -> bool

Source

pub fn is_neg(&self) -> bool

Source

pub fn from_raw(vec: Vec<u32>, is_neg: bool) -> Self

vec is that of UBigInt::from_raw

Source

pub fn into_raw(self) -> (Vec<u32>, bool)

Trait Implementations§

Source§

impl Binary for BigInt

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Clone for BigInt

Source§

fn clone(&self) -> BigInt

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BigInt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BigInt

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for BigInt

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&BigInt> for Ratio

Source§

fn from(n: &BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<&BigInt> for bool

Source§

fn from(n: &BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<&Ratio> for BigInt

Source§

fn from(n: &Ratio) -> Self

Converts to this type from the input type.
Source§

impl From<&UBigInt> for BigInt

Source§

fn from(n: &UBigInt) -> Self

Converts to this type from the input type.
Source§

impl From<&bool> for BigInt

Source§

fn from(n: &bool) -> Self

Converts to this type from the input type.
Source§

impl From<&i128> for BigInt

Source§

fn from(n: &i128) -> Self

Converts to this type from the input type.
Source§

impl From<&i16> for BigInt

Source§

fn from(n: &i16) -> Self

Converts to this type from the input type.
Source§

impl From<&i32> for BigInt

Source§

fn from(n: &i32) -> Self

Converts to this type from the input type.
Source§

impl From<&i64> for BigInt

Source§

fn from(n: &i64) -> Self

Converts to this type from the input type.
Source§

impl From<&i8> for BigInt

Source§

fn from(n: &i8) -> Self

Converts to this type from the input type.
Source§

impl From<&isize> for BigInt

Source§

fn from(n: &isize) -> Self

Converts to this type from the input type.
Source§

impl From<&u128> for BigInt

Source§

fn from(n: &u128) -> Self

Converts to this type from the input type.
Source§

impl From<&u16> for BigInt

Source§

fn from(n: &u16) -> Self

Converts to this type from the input type.
Source§

impl From<&u32> for BigInt

Source§

fn from(n: &u32) -> Self

Converts to this type from the input type.
Source§

impl From<&u64> for BigInt

Source§

fn from(n: &u64) -> Self

Converts to this type from the input type.
Source§

impl From<&u8> for BigInt

Source§

fn from(n: &u8) -> Self

Converts to this type from the input type.
Source§

impl From<&usize> for BigInt

Source§

fn from(n: &usize) -> Self

Converts to this type from the input type.
Source§

impl From<BigInt> for Ratio

Source§

fn from(n: BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<BigInt> for bool

Source§

fn from(n: BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<Ratio> for BigInt

Source§

fn from(n: Ratio) -> Self

Converts to this type from the input type.
Source§

impl From<UBigInt> for BigInt

Source§

fn from(n: UBigInt) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for BigInt

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for BigInt

Source§

fn from(n: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for BigInt

Source§

fn from(n: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for BigInt

Source§

fn from(n: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for BigInt

Source§

fn from(n: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for BigInt

Source§

fn from(n: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for BigInt

Source§

fn from(n: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for BigInt

Source§

fn from(n: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for BigInt

Source§

fn from(n: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for BigInt

Source§

fn from(n: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for BigInt

Source§

fn from(n: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for BigInt

Source§

fn from(n: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for BigInt

Source§

fn from(n: usize) -> Self

Converts to this type from the input type.
Source§

impl FromStr for BigInt

Source§

type Err = ConversionError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for BigInt

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerExp for BigInt

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LowerHex for BigInt

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Octal for BigInt

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for BigInt

Source§

fn cmp(&self, other: &BigInt) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for BigInt

Source§

fn eq(&self, other: &BigInt) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for BigInt

Source§

fn partial_cmp(&self, other: &BigInt) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<&BigInt> for UBigInt

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for f32

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for f64

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for i128

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for i16

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for i32

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for i64

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for i8

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for isize

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for u128

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for u16

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for u32

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for u64

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for u8

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&BigInt> for usize

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&f32> for BigInt

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &f32) -> Result<Self, ConversionError>

Performs the conversion.
Source§

impl TryFrom<&f64> for BigInt

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &f64) -> Result<Self, ConversionError>

Performs the conversion.
Source§

impl TryFrom<&str> for BigInt

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for UBigInt

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for f32

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for f64

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for i128

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for i16

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for i32

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for i64

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for i8

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for isize

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for u128

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for u16

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for u32

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for u64

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for u8

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<BigInt> for usize

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: BigInt) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for BigInt

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<f32> for BigInt

It returns the truncated value of Ratio::from(n).

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: f32) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<f64> for BigInt

It returns the truncated value of Ratio::from(n).

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(n: f64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for BigInt

Source§

impl StructuralPartialEq for BigInt

Auto Trait Implementations§

§

impl Freeze for BigInt

§

impl RefUnwindSafe for BigInt

§

impl Send for BigInt

§

impl Sync for BigInt

§

impl Unpin for BigInt

§

impl UnwindSafe for BigInt

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.