lcm.c 441 B

12345678910111213141516171819202122232425
  1. #include <linux/compiler.h>
  2. #include <linux/gcd.h>
  3. #include <linux/export.h>
  4. #include <linux/lcm.h>
  5. /* Lowest common multiple */
  6. unsigned long lcm(unsigned long a, unsigned long b)
  7. {
  8. if (a && b)
  9. return (a / gcd(a, b)) * b;
  10. else
  11. return 0;
  12. }
  13. EXPORT_SYMBOL_GPL(lcm);
  14. unsigned long lcm_not_zero(unsigned long a, unsigned long b)
  15. {
  16. unsigned long l = lcm(a, b);
  17. if (l)
  18. return l;
  19. return (b ? : a);
  20. }
  21. EXPORT_SYMBOL_GPL(lcm_not_zero);