blob: 3657f129d7b8c5db0bee11a94a97d5d4bf251b52 [file] [log] [blame]
Florian Fainellid2829222009-06-17 16:28:38 -07001#include <linux/kernel.h>
2#include <linux/gcd.h>
Paul Gortmaker8bc3bcc2011-11-16 21:29:17 -05003#include <linux/export.h>
Florian Fainellid2829222009-06-17 16:28:38 -07004
5/* Greatest common divisor */
6unsigned long gcd(unsigned long a, unsigned long b)
7{
8 unsigned long r;
9
10 if (a < b)
11 swap(a, b);
Davidlohr Buesoe9687562012-10-04 17:13:18 -070012
13 if (!b)
14 return a;
Florian Fainellid2829222009-06-17 16:28:38 -070015 while ((r = a % b) != 0) {
16 a = b;
17 b = r;
18 }
19 return b;
20}
21EXPORT_SYMBOL_GPL(gcd);