Struct clacc::gmp::BigInt

source ·
pub struct BigInt { /* private fields */ }
Expand description

Implementation of BigInt using rust-gmp.

Trait Implementations§

use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let a: BigInt = 18.into();
let b: BigInt = 2.into();
let c = a.add(&b);
assert_eq!(c, (18 + 2).into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let a: BigInt = 18.into();
let b: BigInt = 2.into();
let c = a.sub(&b);
assert_eq!(c, (18 - 2).into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let a: BigInt = 18.into();
let b: BigInt = 2.into();
let c = a.mul(&b);
assert_eq!(c, (18 * 2).into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let a: BigInt = 18.into();
let b: BigInt = 2.into();
let c = a.div(&b);
assert_eq!(c, (18 / 2).into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let x: BigInt = 240.into();
let y: clacc::gmp::BigInt = 46.into();
let (g, a, b) = x.gcdext(&y);
assert_eq!(g, 2.into());
assert_eq!(a, (-9).into());
assert_eq!(b, 47.into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let b: BigInt = 11.into();
let n: BigInt = 7.into();
let m = b.modulus(&n);
assert_eq!(m, 4.into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let b: BigInt = 5.into();
let e: BigInt = 3.into();
let m: BigInt = 13.into();
let c = b.powm(&e, &m);
assert_eq!(c, 8.into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let a: BigInt = 123.into();
let n: BigInt = 4567.into();
let i = a.invert(&n).unwrap();
assert_eq!(i, 854.into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let x: BigInt = 32.into();
let p = x.next_prime();
assert_eq!(p, 37.into());
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let a: BigInt = 3.into();
assert_eq!(a.size_in_bits(), 2);
let b: BigInt = 256.into();
assert_eq!(b.size_in_bits(), 9);
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let x: BigInt = 15.into();
assert_eq!(x.to_vec(), vec![0x0f]);
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Formats the value using the given formatter.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. 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
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
use clacc::{BigInt as BigIntTrait, gmp::BigInt};
let x: BigInt = 6666666666.into();
let bytes = velocypack::to_bytes(&x).unwrap();
let de = velocypack::from_bytes(&bytes).unwrap();
assert_eq!(x, de);
Formats the value using the given formatter.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.