Expand description
List the prime factors of a number or fraction using the Fraction
type. Uses the
prime_factorization
library.
Examples
Basic usage:
let frac = Fraction::whole(84);
let factors: Vec<Factor> = frac.factorize().collect();
assert_eq!(factors, [
Factor::Prime(2, 2),
Factor::Prime(3, 1),
Factor::Prime(7, 1),
]);
Factorize a fraction:
let frac = Fraction::new(-1370, 56);
let factors: Vec<Factor> = frac.factorize().collect();
assert_eq!(factors, [
Factor::NegativeOne,
Factor::Prime(2, -2),
Factor::Prime(5, 1),
Factor::Prime(7, -1),
Factor::Prime(137, 1),
]);
Reduce a fraction:
let frac = Fraction::new(1200, 362);
let reduced: Fraction = frac.factorize().product();
assert_eq!(reduced, Fraction::new(600, 181));
Structs
- A fraction that can be factorized.
Enums
- A prime factor of a fraction.