[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] lcm
From: |
Bruno Haible |
Subject: |
Re: [Bug-gnulib] lcm |
Date: |
Tue, 2 Nov 2004 22:10:03 +0100 |
User-agent: |
KMail/1.5 |
Hi,
> unsigned long
> lcm(unsigned long a, unsigned long b)
> {
> return labs(a * b) / gcd(a, b);
> }
What is the 'labs' call good for, since a and b are unsigned?
Also your formula will needlessly overflow; take for example
a = 72344 and b = 70212 on a 32-bit machine.
So we arrive at
a * (b / gcd (a, b))
or, equivalently,
(a / gcd (a, b)) * b.
But since it's a one-liner, there's no point in putting it into gnulib.
Bruno