diff options
author | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2015-08-05 17:04:01 -0300 |
---|---|---|
committer | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2015-08-05 17:04:01 -0300 |
commit | 57f0f512b273f60d52568b8c6b77e17f5636edc0 (patch) | |
tree | 5e910f0e82173f4ef4f51111366a3f1299037a7b /lib/gcd.c |
Initial import
Diffstat (limited to 'lib/gcd.c')
-rw-r--r-- | lib/gcd.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/gcd.c b/lib/gcd.c new file mode 100644 index 000000000..3657f129d --- /dev/null +++ b/lib/gcd.c @@ -0,0 +1,21 @@ +#include <linux/kernel.h> +#include <linux/gcd.h> +#include <linux/export.h> + +/* Greatest common divisor */ +unsigned long gcd(unsigned long a, unsigned long b) +{ + unsigned long r; + + if (a < b) + swap(a, b); + + if (!b) + return a; + while ((r = a % b) != 0) { + a = b; + b = r; + } + return b; +} +EXPORT_SYMBOL_GPL(gcd); |