Link Details

Link 33929 thumbnail
User 1 avatar

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.
  • 20
  • 3
  • 1796
  • 543

Comments

Add your comment
User 239008 avatar

keeish replied ago:

0 votes Vote down Vote up Reply

incomprehensibly difficult text. requires ph.d to even understand. someone please translate it to a human language.

User 239008 avatar

keeish replied ago:

0 votes Vote down Vote up Reply

also it is not a tutorial!

User 233461 avatar

antych replied ago:

0 votes Vote down Vote up Reply

I don't want to know it, this article is to long for my attention span...

User 210175 avatar

jtheory replied ago:

0 votes Vote down Vote up Reply

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

User 209827 avatar

evarlast replied ago:

0 votes Vote down Vote up Reply

@theory

.NET has a nice decimal type which is great for currency. It has 128bits of precision.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.