2019-05-19 20:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-02-13 07:03:21 +08:00
|
|
|
#include <linux/compiler.h>
|
2010-03-15 19:46:51 +08:00
|
|
|
#include <linux/gcd.h>
|
2011-11-17 10:29:17 +08:00
|
|
|
#include <linux/export.h>
|
2011-07-26 08:13:20 +08:00
|
|
|
#include <linux/lcm.h>
|
2010-03-15 19:46:51 +08:00
|
|
|
|
|
|
|
/* Lowest common multiple */
|
|
|
|
unsigned long lcm(unsigned long a, unsigned long b)
|
|
|
|
{
|
|
|
|
if (a && b)
|
2014-12-11 07:51:27 +08:00
|
|
|
return (a / gcd(a, b)) * b;
|
2014-12-11 07:51:29 +08:00
|
|
|
else
|
|
|
|
return 0;
|
2010-03-15 19:46:51 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(lcm);
|
2015-03-31 01:39:09 +08: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);
|