2015-02-12 16:03:21 -07:00
|
|
|
#include <linux/compiler.h>
|
2010-03-15 05:46:51 -06:00
|
|
|
#include <linux/gcd.h>
|
2011-11-16 19:29:17 -07:00
|
|
|
#include <linux/export.h>
|
2011-07-25 18:13:20 -06:00
|
|
|
#include <linux/lcm.h>
|
2010-03-15 05:46:51 -06:00
|
|
|
|
|
|
|
/* Lowest common multiple */
|
|
|
|
unsigned long lcm(unsigned long a, unsigned long b)
|
|
|
|
{
|
|
|
|
if (a && b)
|
2014-12-10 16:51:27 -07:00
|
|
|
return (a / gcd(a, b)) * b;
|
2014-12-10 16:51:29 -07:00
|
|
|
else
|
|
|
|
return 0;
|
2010-03-15 05:46:51 -06:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(lcm);
|
2015-03-30 11:39:09 -06:00
|
|
|
|
|
|
|
unsigned long lcm_not_zero(unsigned long a, unsigned long b)
|
|
|
|
{
|
|
|
|
unsigned long l = lcm(a, b);
|
|
|
|
|
|
|
|
if (l)
|
|
|
|
return l;
|
|
|
|
|
|
|
|
return (b ? : a);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(lcm_not_zero);
|