Skip to main content

Integer

Struct Integer 

Source
pub struct Integer(/* private fields */);
Expand description

Arbitrary-precision integer backed by num-bigint.

§Example

use ocas_domain::Integer;

let a = Integer::from(42);
let b = Integer::new(100);
assert_eq!(a.to_string(), "42");
assert_eq!(b.to_string(), "100");

Implementations§

Source§

impl Integer

Source

pub fn new<T: Into<BigInt>>(value: T) -> Self

Create an integer from a machine integer.

Source

pub fn inner(&self) -> &BigInt

Access the underlying BigInt.

Source

pub fn to_bigint(&self) -> BigInt

Convert to a BigInt regardless of the backend.

Source

pub fn to_i64(&self) -> Option<i64>

Try to extract the value as i64. Returns None if it doesn’t fit.

Source

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

Raise to a u32 power.

Source§

impl Integer

Source

pub fn modpow(&self, exp: &Integer, modulus: &Integer) -> Integer

Modular exponentiation: self^exp mod modulus.

Source

pub fn mod_floor(&self, modulus: &Integer) -> Integer

Floor modulo: result r satisfies 0 ≤ r < |modulus|.

Source

pub fn div_rem(&self, other: &Integer) -> (Integer, Integer)

Division with remainder: (quotient, remainder).

Source

pub fn is_even(&self) -> bool

Returns true if the value is even.

Source

pub fn is_negative(&self) -> bool

Returns true if the value is negative.

Source

pub fn is_zero(&self) -> bool

Returns true if the value is zero.

Source

pub fn is_one(&self) -> bool

Returns true if the value is one.

Source

pub fn abs(&self) -> Integer

Absolute value.

Source

pub fn sqrt(&self) -> Integer

Integer square root (floor).

Trait Implementations§

Source§

impl Add for Integer

Source§

type Output = Integer

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Integer) -> Integer

Performs the + operation. Read more
Source§

impl Add<&Integer> for Integer

Source§

type Output = Integer

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Integer) -> Integer

Performs the + operation. Read more
Source§

impl Add<&Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Integer) -> Integer

Performs the + operation. Read more
Source§

impl Add<Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Integer) -> Integer

Performs the + operation. Read more
Source§

impl AddAssign<&Integer> for Integer

Available on non-crate feature gmp only.
Source§

fn add_assign(&mut self, rhs: &Integer)

Performs the += operation. Read more
Source§

impl Clone for Integer

Source§

fn clone(&self) -> Integer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Integer

Source§

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

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

impl Display for Integer

Available on non-crate feature gmp only.
Source§

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

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

impl Div for Integer

Source§

type Output = Integer

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Integer) -> Integer

Performs the / operation. Read more
Source§

impl Div<&Integer> for Integer

Source§

type Output = Integer

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Integer) -> Integer

Performs the / operation. Read more
Source§

impl Div<&Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Integer) -> Integer

Performs the / operation. Read more
Source§

impl Div<Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Integer) -> Integer

Performs the / operation. Read more
Source§

impl DivAssign<&Integer> for Integer

Available on non-crate feature gmp only.
Source§

fn div_assign(&mut self, rhs: &Integer)

Performs the /= operation. Read more
Source§

impl Eq for Integer

Source§

impl From<BigInt> for Integer

Available on non-crate feature gmp only.
Source§

fn from(value: BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Integer

Available on non-crate feature gmp only.
Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl Hash for Integer

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 Mul for Integer

Source§

type Output = Integer

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Integer) -> Integer

Performs the * operation. Read more
Source§

impl Mul<&Integer> for Integer

Source§

type Output = Integer

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Integer) -> Integer

Performs the * operation. Read more
Source§

impl Mul<&Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Integer) -> Integer

Performs the * operation. Read more
Source§

impl Mul<Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Integer) -> Integer

Performs the * operation. Read more
Source§

impl MulAssign<&Integer> for Integer

Available on non-crate feature gmp only.
Source§

fn mul_assign(&mut self, rhs: &Integer)

Performs the *= operation. Read more
Source§

impl Neg for Integer

Available on non-crate feature gmp only.
Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn neg(self) -> Integer

Performs the unary - operation. Read more
Source§

impl Neg for &Integer

Available on non-crate feature gmp only.
Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn neg(self) -> Integer

Performs the unary - operation. Read more
Source§

impl Ord for Integer

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · 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 Integer

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Integer

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Rem for Integer

Source§

type Output = Integer

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Integer) -> Integer

Performs the % operation. Read more
Source§

impl Rem<&Integer> for Integer

Source§

type Output = Integer

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &Integer) -> Integer

Performs the % operation. Read more
Source§

impl Rem<&Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &Integer) -> Integer

Performs the % operation. Read more
Source§

impl Rem<Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Integer) -> Integer

Performs the % operation. Read more
Source§

impl Shr<u32> for Integer

Available on non-crate feature gmp only.
Source§

type Output = Integer

The resulting type after applying the >> operator.
Source§

fn shr(self, shift: u32) -> Integer

Performs the >> operation. Read more
Source§

impl Shr<u32> for &Integer

Available on non-crate feature gmp only.
Source§

type Output = Integer

The resulting type after applying the >> operator.
Source§

fn shr(self, shift: u32) -> Integer

Performs the >> operation. Read more
Source§

impl ShrAssign<u32> for Integer

Available on non-crate feature gmp only.
Source§

fn shr_assign(&mut self, shift: u32)

Performs the >>= operation. Read more
Source§

impl StructuralPartialEq for Integer

Source§

impl Sub for Integer

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Integer) -> Integer

Performs the - operation. Read more
Source§

impl Sub<&Integer> for Integer

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Integer) -> Integer

Performs the - operation. Read more
Source§

impl Sub<&Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Integer) -> Integer

Performs the - operation. Read more
Source§

impl Sub<Integer> for &Integer

Source§

type Output = Integer

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Integer) -> Integer

Performs the - operation. Read more
Source§

impl SubAssign<&Integer> for Integer

Available on non-crate feature gmp only.
Source§

fn sub_assign(&mut self, rhs: &Integer)

Performs the -= operation. Read more

Auto Trait Implementations§

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, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T, Base> RefNum<Base> for T
where T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,

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.