• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BigDecimal and the lack of information about rounding

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Janet Wilson
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dirk,
As usual - thanks!
I might even beat you to it because we've found all sorts of information concerning this:
IBM's Alphaworks BigDecimal Overview
IBM's General Decimal Arithmetic (contains many links)
IEEE 754-1985: Standard for Binary Floating-Point Arithmetic
IEEE 854-1987: Standard for Radix-Independent Floating-Point Arithmetic
What Every Computer Scientist Should Know About Floating-Point Arithmetic
It still just struck us as being odd that coverage isn't at least "strongly" mentioned. Please add your links if they are not amongst these.
Thanks! Janet
P.S.-Credit to "JJ" at my work for the links.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Janet Wilson
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the additional info Dirk!
Janet
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic