pub struct LargeInt {
pub digits: String,
pub sign: Sign,
}
Arithmetic is carried out on instances of LargeInt. The scalar value is stored
in a String and its sign in the enum Sign.
Stores the scalar value of the LargeInt as a String.
Stores the sign of the value as a Sign.
Returns a copy of the scalar LargeInt value as a String.
Returns the Sign of the LargeInt value as a String.
Compares the scalar value of two LargeInts.
extern crate largeint;
use largeint::largeint::*;
let largeint1 = new(String::from("150"), Sign::Positive);
let largeint2 = new(String::from("100"), Sign::Positive);
assert_eq!(largeint1.compare(&largeint2), Compare::Larger);
Adds two LargeInts together.
extern crate largeint;
use largeint::largeint::*;
let largeint1 = new(String::from("80000000000000000000000000000"), Sign::Positive);
let largeint2 = new(String::from("10000000000000000000000000000"), Sign::Positive);
let sum = largeint1.add(&largeint2);
let check = new(String::from("90000000000000000000000000000"), Sign::Positive);
assert_eq!(sum, check);
Subtracts a LargeInt from another.
extern crate largeint;
use largeint::largeint::*;
let largeint1 = new(String::from("80000000000000000000000000000"), Sign::Positive);
let largeint2 = new(String::from("10000000000000000000000000000"), Sign::Positive);
let sum = largeint1.sub(&largeint2);
let check = new(String::from("70000000000000000000000000000"), Sign::Positive);
assert_eq!(sum, check);
Multiplies two LargeInts together.
extern crate largeint;
use largeint::largeint::*;
let largeint1 = new(String::from("1110987654321"), Sign::Positive);
let largeint2 = new(String::from("1234567891011"), Sign::Negative);
let sum = largeint1.mul(&largeint2);
let check = new(String::from("1371589685334334871208531"), Sign::Negative);
assert_eq!(sum, check);
Divides one LargeInt by another LargeInt.
extern crate largeint;
use largeint::largeint::*;
let largeint1 = new(String::from("3987382479238749823798759823745983748927"), Sign::Negative);
let largeint2 = new(String::from("98394783947982377583783759928"), Sign::Negative);
let sum = largeint1.div(&largeint2);
let check = new(String::from("40524327807"), Sign::Positive);
assert_eq!(sum, check);
Returns the remainder of a floor division operation.
extern crate largeint;
use largeint::largeint::*;
let largeint1 = new(String::from("3987382479238749823798759823745983748927"), Sign::Negative);
let largeint2 = new(String::from("98394783947982377583783759928"), Sign::Negative);
let sum = largeint1.rem(&largeint2);
let check = new(String::from("31770318334258129020721031031"), Sign::Positive);
assert_eq!(sum, check);
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Formats the value using the given formatter. Read more
Performs copy-assignment from source
. Read more