Re: This calculation is just wrong / computer can't count!
- From: "GT" <ContactGT_removeme_@xxxxxxxxxxx>
- Date: Thu, 4 Oct 2007 17:14:48 +0100
"Les" <l.neilson@xxxxxxxxxxxxxxxxxxx> wrote in message
news:fe327n$10cj$1@xxxxxxxxxxxxxxxxxxxx
"GT" <ContactGT_removeme_@xxxxxxxxxxx> wrote in message
news:00238cdd$0$5102$c3e8da3@xxxxxxxxxxxxxxxxxxxx
"AliR (VC++ MVP)" <AliR@xxxxxxxxxxxxx> wrote in message
news:En7Ni.30834$eY.28056@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Maybe this will clear some of it up:
http://www.google.com/search?q=Significant+digits+double&hl=en
That info on significant digits was all very interesting, but how do I
get my code to work properly?!? I want to force the computer to calculate
and store as many digits as it can handle and no extra spurious digits,
so that my calculations get nice accurate results. At the moment part of
my calculation ends up with -0.00000000000007 (haven't counted the zeros
here, but you get the idea!), where it should be zero.
If your algorithm is susceptible to differences at the 17th decimal place
(as in your original post) then your algorithm is wrong.
There are an infinite number of numbers between 0.830 and 0.840 (ie
between *any* two numbers) unfortunately computers only have a limited
number of bytes in which to store these numbers, and a "standard defined"
way of storing them if it uses for example IEEE format.
Many numbers cannot be represented exactly in binary and so a compromise
is assumed.
If you were to try "by hand" your calculation, then the recurring 3's of
25.0/30.0 would cause you to run out of paper before you could do the
actual math. So you mentally adjust the *correct* number to (an incorrect)
one which you can handle.
Almost - your last part is wrong. You don't *adjust* the number, you
*truncate* the number to a certain level of precision. Even if you truncate
the number to 2 decimal places it is 0.83 not 0.87 !!
In the case of double the level of precision seems to be 16 digits, but this
is actually irrelevant. Whatever the number of digits used, the last digit
should be a 3 not a 7 !! My algorithm is fine, the calculation is producing
an incorrect answer. At a point later in my calculation I end up subtracting
one number from another and the answer should be zero, but instead (due to
the above problem) the answer is not == 0.
.
- Follow-Ups:
- Re: This calculation is just wrong / computer can't count!
- From: Joseph M . Newcomer
- Re: This calculation is just wrong / computer can't count!
- From: Alexander Grigoriev
- Re: This calculation is just wrong / computer can't count!
- From: Les
- Re: This calculation is just wrong / computer can't count!
- References:
- Prev by Date: Re: This calculation is just wrong / computer can't count!
- Next by Date: Re: This calculation is just wrong / computer can't count!
- Previous by thread: Re: This calculation is just wrong / computer can't count!
- Next by thread: Re: This calculation is just wrong / computer can't count!
- Index(es):
Relevant Pages
|