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.
We ran up against a rounding "problem" in Java which we were unaware of. We have since discovered that if we want exact results we need to use the BigDecimal API or we could use int or long if we want to keep track of the decimal (look at Joshua Bloch's item #31 in "Effective Java"). However, my post isn't technical, per se. We (there's 2 of us at my job who are really curious about this) are surprised at the dearth of literature concerning this topic and was wondering if we were somehow snoozing during the beginner's coverage on the Sun site or if they only talk about this problem in formal classes or ??? I would think this topic would be covered extensively in a beginner's guide under their "gotcha's section"? Are there any other gotcha's (besides what Joshua Bloch uncovers in his book) one should be aware of? Could someone explain why there is little written about this topic? Thanks in advance for enlightening me. Janet P.S.-I thought it was funny that at the JavaOne 2003 conference they are offering a session called: BigInteger, BigDecimal, and a Billion of digits of Pi (ts-1991)
This isn't a Java specific issue, so perhaps that's why you haven't stumbled across much coverage on the topic. The loss of precision with floating-point arithmetic is a bit of a techincal matter concerning bit patterns and the size of a given data type. A good computer science book on computer architecture should describe well the topic of floating-point data types and the IEEE 754 standard (which Java follows). Some place in the cattle drive forum (and in this forum) is a reference to a decent article or two on the subject. I've it book marked at home and will post it later if somebody else doesn't beat me to it.
Not everybody has neglected to include this topic in their development of introductory Java curriculum. The purpose of the Sum assignment of The JavaRanch Cattle Drive is to become familiar with this very topic. You've found some good resources. You may also want to take a look at the Cattle Drive Forum conversation I previously mentioned and from which I now quote:
Originally posted by Richard Boren: Peter van der Linden, author of Just Java 2, maintains a Java FAQ list at Java Software, FAQs, Books. The fourth question, under Java Programming Language Issues of the FAQ, explains floating point errors plus it has two additional links that give in-depth explanation of floating point.
Joined: Jul 16, 2002
Thanks for the additional info Dirk! Janet
subject: BigDecimal and the lack of information about rounding