This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I suppose it depends on what the purpose of your Fraction class is. Is your goal to create an exact representation of a fraction like 1/3? Or will you be satisfied with convenient alternatives like 0.3333333333? If it's the former, I would use only exact integer types for the numerator and denominator - int, long, or BigInteger. Floating-point arithmentic frequently has small roundoff errors; it's inherent in the format. If you're OK with approximations - then why do you need ths Fraction class at all? For computations you might just as well convert everything to doubles. However, you may have some other reason for this class, which I am unaware of. Care to provide more details on what you're trying to do?
Originally posted by Stan James: There are languages that maintain numbers like that. Anybody ever use one?
I'm currently playing with Squeak, a modern Smalltalk dialect. Smalltalk has a Fraction class and uses it fully transparently since ages.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus