gcd_bitwise
Disclaimer: The code is not mine.
The code is part of the coreutils project. I have forked it for ease of use, for those who dont want to pull in big dependencies for calculating gcd.
Big Update!
You can pass any numeric type into gcd()
function. If you pass 2 u16
type, the result you will get will be
the same u16
. You can pass u8
, u16
, u32
, u64
and hell, even usize
. Please have a look at the Quick Start part below for examples.
Some Notes
This code uses stein's algorithm, that replaces division with arithmetic shifts, comparisons, and subtraction, for optimization of performance. For more info on how efficient this algorithm is, please refer to this page.
Quick Start
use gcd;
version_note: Made the api simpler to use. Please refer to the repository for the documentation, if you find that docs.rs
didn't build the docs for latest version.