By rick
via docs.sun.com
Published: Aug 07 2007 / 17:51
This paper presents a tutorial on those aspects of floating-point that have a direct impact on designers of computer systems. It begins with background on floating-point representation and rounding error, continues with a discussion of the IEEE floating-point standard, and concludes with numerous examples of how computer builders can better support floating-point.
Tweet
SaveShareSend
Tags: methodology



Comments
keeish replied ago:
incomprehensibly difficult text. requires ph.d to even understand. someone please translate it to a human language.
keeish replied ago:
also it is not a tutorial!
antych replied ago:
I don't want to know it, this article is to long for my attention span...
jtheory replied ago:
Okay, over my head as well.
But it's important to know a *few* things at least about floating point calculations if you're a developer -- particularly if you ever deal with currency (and we pretty much all do...), because of the tiny error that's basically unavoidable in floating point calculations.
For example, try this in Java:
float result = 1.68f - 1.10f;
System.out.println( "result will be 0.58 of course... right?: " + result );
Nope. "I know", you say, "use double instead of float... lots more significant digits!".
Well, try it.
This is a huge gotcha. Floating point math is fine for most things, where a tiny fraction difference won't matter, but for currency it's simply dangerous.
There are multiple ways to dodge the "missing pennies" problem:
* Store currencies as pennies, and just add the decimal point for display (so all your arithmetic will be int arithmetic).
* Use BigDecimal for currency
evarlast replied ago:
@theory
.NET has a nice decimal type which is great for currency. It has 128bits of precision.
Voters For This Link (21)
Voters Against This Link (3)