mirror of
https://github.com/fail0verflow/switch-linux.git
synced 2025-05-04 02:34:21 -04:00
lib/lcm.c: ensure correct result whenever it fits
Ensure that lcm(a,b) returns the mathematically correct result, provided it fits in an unsigned long. The current version returns garbage if a*b overflows, even if the final result would fit. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
7b212edf86
commit
74a5fef7cb
1 changed files with 1 additions and 1 deletions
|
@ -7,7 +7,7 @@
|
|||
unsigned long lcm(unsigned long a, unsigned long b)
|
||||
{
|
||||
if (a && b)
|
||||
return (a * b) / gcd(a, b);
|
||||
return (a / gcd(a, b)) * b;
|
||||
else if (b)
|
||||
return b;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue