big_num_math 7.0.0

Unostentatious and internally banal library for computations on large numbers.
Documentation

BIG NUM MATH

Unostentatious library for computations on large numbers.

Internally banal, based on long form arithmetic methods of: addition, subtraction, multiplication and division.

  • upcomming functions:
    • multiplicative modular inverse
    • negative numbers support
  • functions:
    • addition +substraction,
    • multiplication +division (with remainder)
    • relation and decimal relation operators
    • order of magnitude
    • power +nth root
    • integer square root
    • primality check
    • prime number generator (primitive number types only)
    • greatest common divisor +extended greatest common divisor

Usage Samples

power
let row = PlacesRow::new_from_u128(u128::MAX);
let pow = pow(&row, 500);
let number = pow.to_number();

assert!(number.starts_with("8312324609993336522"));
assert_eq!(19266, number.len());
division with remainder
let dividend = PlacesRow::new_from_str("3402823669209384634633746074317682114565556668744123").unwrap();
let divisor  = PlacesRow::new_from_str(  "14034568236692093846346337460345176821145655563453").unwrap();
let ratio = "242";        
let remainder = "6458155929897923817932408914149323848308022388497";
        
let ratrem = divrem(&dividend, &divisor).unwrap();
        
assert_eq!(ratio, ratrem.0.to_number());
assert_eq!(remainder, ratrem.1.to_number());
let dividend = Row::new_from_str("99999340282366920938463463374607431768211455").unwrap();
let divisor  = Row::new_from_usize(249);

let ratio     = Row::new_from_str("401603776234405304973748848894005750073138").unwrap();
let remainder = Row::new_from_usize(93);

let ratrem = divrem(&dividend, &divisor).unwrap();
assert_eq!(ratio, ratrem.0);
assert_eq!(remainder, ratrem.1);
decimal places relation
let number    = Row::new_from_str("1489754132134687989463132131").unwrap();
let comparand = Row::new_from_str(        "48645698946456531371").unwrap();

let number_places = number.places();
let comparand_places = comparand.places();

let decrel = rel_dec(&number, &comparand);            
let places_details = DecCnt(number_places, comparand_places);
assert_eq!(RelDec::Greater(places_details), decrel);
order of magnitude
let number_1 = PlacesRow::new_from_u128(3162277660168379331998893544432);
let number_2 = PlacesRow::new_from_u128(3162277660168379331998893544433);

assert_eq!(Oom::Precise(30), ord_of_mag(&number_1, OomClass::Strict));
assert_eq!(Oom::Precise(31), ord_of_mag(&number_2, OomClass::Strict));
assert_eq!(Oom::Precise(30), ord_of_mag(&number_2, OomClass::Loose));
square root
let radicand  = Row::new_from_str("9754610577924096936222542295378750190521").unwrap();
let test = Row::new_from_u128(98_765_432_100_123_456_789);
assert_eq!(test, heron_sqrt(&radicand));
primality check
let num = Row::new_from_str("340282366920938463463374607431768211479").unwrap();
let limit = Duration::from_secs(3);
assert_eq!(Some(false), prime_ck(&num, Some(limit)));
prime number generation
let limit = Duration::from_secs(60);
let p = || pg!(200_000, PrimeGenClass::Nth, false, u32, Some(limit));
assert_eq!(Ok(PrimeGenRes::Max(2_750_159)), p());
nth root
let test = PlacesRow::new_from_usize(99_999_999);
let radicand = PlacesRow::new_from_str(
    "999999910000003599999916000001259999987400000083999999640000000899999999",
)
.unwrap();
assert_eq!(Some(test), root(&radicand, 9));
greatest common divisor
let num1 = PlacesRow::new_from_u128(u128::MAX / 5);
let num2 = PlacesRow::new_from_u64(u64::MAX / 5);
let proof = PlacesRow::new_from_str("3689348814741910323").unwrap();

let gcd = gcd(&num1, &num2, GcdClass::Euclid);
assert_eq!(proof, gcd.uproot_gcd());