gcd.c 313 B

12345678910111213141516171819202122
  1. #include <linux/kernel.h>
  2. #include <linux/gcd.h>
  3. #include <linux/export.h>
  4. /* Greatest common divisor */
  5. unsigned long gcd(unsigned long a, unsigned long b)
  6. {
  7. unsigned long r;
  8. if (a < b)
  9. swap(a, b);
  10. if (!b)
  11. return a;
  12. while ((r = a % b) != 0) {
  13. a = b;
  14. b = r;
  15. }
  16. return b;
  17. }
  18. EXPORT_SYMBOL_GPL(gcd);