Skip to main content

gcd_binary

Function gcd_binary 

Source
pub fn gcd_binary(a: BigInt, b: BigInt) -> BigInt
Expand description

Binary GCD (Stein’s algorithm) - more efficient than Euclidean GCD.

This algorithm uses bitwise operations instead of division, making it faster for large integers.

§Examples

use num_bigint::BigInt;
use oxiz_math::rational::gcd_binary;

assert_eq!(gcd_binary(BigInt::from(48), BigInt::from(18)), BigInt::from(6));
assert_eq!(gcd_binary(BigInt::from(100), BigInt::from(35)), BigInt::from(5));
assert_eq!(gcd_binary(BigInt::from(17), BigInt::from(19)), BigInt::from(1));