pub const fn gcd(left: u64, right: u64) -> u64Expand description
Computes the greatest common divisor of two unsigned integers.
This helper uses the Euclidean algorithm and keeps the required edge cases
explicit: gcd(0, 0) == 0 and gcd(a, 0) == a.
ยงExamples
use use_arithmetic::gcd;
assert_eq!(gcd(54, 24), 6);
assert_eq!(gcd(0, 0), 0);
assert_eq!(gcd(21, 0), 21);Examples found in repository?
examples/basic_usage.rs (line 7)
6fn main() {
7 assert_eq!(gcd(54, 24), 6);
8 assert_eq!(lcm(6, 15), 30);
9 assert!(is_divisible_by(84, 7));
10 assert!(is_even(12));
11 assert!(is_odd(7));
12 assert_eq!(div_floor(-7, 3), -3);
13 assert_eq!(mod_floor(-7, 3), 2);
14 assert_eq!(checked_add(u8::MAX, 1), None);
15 assert_eq!(saturating_add(u8::MAX, 1), u8::MAX);
16 assert_eq!(wrapping_mul(200_u8, 2), 144);
17}