Click to See Complete Forum and Search --> : Common divider for fractional numbers


bendenj
January 7th, 2008, 09:49 AM
Hi Gurus,

I'm looking for a way to find a most common divider
for 2 numbers.

There are many algorithms out there, but all of them are for
integer numbers only.

I'm looking for code or an alogrithm idea that will deliver the
same, but for 2 float/double numbers.

For example:

4.44 and 39.96 has great common divider of : 4.44

4.44 and 6.66 has : 2.22

etc...


Any help would be highly appreciated,

Thanks!

Josh.

Zachm
January 7th, 2008, 01:53 PM
1. If your 2 floating point numbers have x digits and y digits respectively, to the right of the decimal point, then assuming x > y, multiple both numbers by 10^x and you have 2 integer numbers.

2. Now find the greatest common denominator using a known algorithm
for integer numbers (like euclid's GCD algorithm).

3. Divide the result by 10^x.

4. That's it !

Regards,
Zachm.