Lowest Common Denominator

Discuss all kind of algorithms and data structures from their mathematical and programming sides.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Postby Alvaro » Wed Apr 26, 2006 8:08 am

If the answer you want is something like "133.33Ohms", then doing computations with fractions is overkill. Just use the type "double" to do all your operations, and you'll be fine.

If you want to use fractions, the least common denominator is the same thing as the least common multiple. For two numbers, lcm(a,b,)*gcd(a,b)=a*b, so you can compute it as a*(b/gcd(a,b)). The standard method to compute the gcd is Euclid's Algorithm: http://en.wikipedia.org/wiki/Euclid%27s_algorithm

For more than two numbers, notice that lcm(a,b,c) = lcm(lcm(a,b),c)
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA


Return to Algorithms & Data Structures

Who is online

Users browsing this forum: Google [Bot] and 3 guests