Best Practice for Dealing with double inaccuracies

J

JBeerhalter

I understand why doubles are not entirely accurate(i.e. if I store the
number .10 in a double it might actually have the value .
100000000001), I was just curious if someone could direct me toward
best practices for dealing with them.

I could cleary eschew double in favor of decimal, or just constantly
round everything, but these seem to involve alot of overhead that I'd
rather not deal with.

-JB
 
D

David Wilkinson

I understand why doubles are not entirely accurate(i.e. if I store the
number .10 in a double it might actually have the value .
100000000001), I was just curious if someone could direct me toward
best practices for dealing with them.

I could cleary eschew double in favor of decimal, or just constantly
round everything, but these seem to involve alot of overhead that I'd
rather not deal with.

Why do you think it matters? If you are doing something that would be
defeated by this "inaccuracy", don't do it.
 
C

Carl Daniel [VC++ MVP]

I understand why doubles are not entirely accurate(i.e. if I store the
number .10 in a double it might actually have the value .
100000000001), I was just curious if someone could direct me toward
best practices for dealing with them.

I could cleary eschew double in favor of decimal, or just constantly
round everything, but these seem to involve alot of overhead that I'd
rather not deal with.

Use your favorite web search tool to find the article "What every computer
scientist should know about floating point arithmetic". There are various
copies of it all over the place. It'll tell you more than you wanted to
know (but not more than you need to know!)

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top