swh:1:snp:77163734605b0ec556b01d897b7bb4a7e30d46b6
Raw File
Tip revision: 2ea659a9ef488125eb46da6eb571de5eae5c43f6 authored by Linus Torvalds on 13 May 2017, 20:19:49 UTC
Linux 4.12-rc1
Tip revision: 2ea659a
lcm.c
#include <linux/compiler.h>
#include <linux/gcd.h>
#include <linux/export.h>
#include <linux/lcm.h>

/* Lowest common multiple */
unsigned long lcm(unsigned long a, unsigned long b)
{
	if (a && b)
		return (a / gcd(a, b)) * b;
	else
		return 0;
}
EXPORT_SYMBOL_GPL(lcm);

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);
back to top