Re: This calculation is just wrong / computer can't count!
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Mon, 08 Oct 2007 16:27:15 -0400
Being a FORTRAN programmer is clearly to your advantage. When we learned FORTRAN (which
was also my first language) these things were carefully explained to us. We did not have
the same delusional expectations as the OP because we knew better.
Apparently he is incapable of learning anything. We've tried. He just won't give up his
delusional system.
joe
On Mon, 8 Oct 2007 15:02:01 +0100, "Les" <l.neilson@xxxxxxxxxxxxxxxxxxx> wrote:
Joseph M. Newcomer [MVP]
"GT" <ContactGT_remove_@xxxxxxxxxxx> wrote in message
news:00616abc$0$12577$c3e8da3@xxxxxxxxxxxxxxxxxxxx
"Les" <l.neilson@xxxxxxxxxxxxxxxxxxx> wrote in message
news:fed0ig$17u6$1@xxxxxxxxxxxxxxxxxxxx
"GT" <ContactGT_remove_@xxxxxxxxxxx> wrote in message
news:005c4583$0$2857$c3e8da3@xxxxxxxxxxxxxxxxxxxx
I have no idea why you are insisting that you are getting the wrong
answers. [snip]
Then you need to go back to primary school mathematics classes!
OK.
So hundreds of thousands of us programmers need to go back to school.
Millions of PCs need to be recalled because "the math is wrong".
Alternatively you could find a class or textbook on Numerical Methods and
computing.
What is 25/30?
In integer math it is 0
In floating point math 0.833333 approximately
I was going to try not to respond but ...
This is my point exactly - it is NOT 0.833337. That number is WRONG.
By your own argument :
0.8333330 is also wrong.
You (or the computer) has introduced an erroneous "0" at whichever point you
put the "truncation".
also
(a) guard bits (digits)
4 days ago, my first reply, the reference to Goldberg's paper. See the
section on "Rounding Error" it is very near the top, it covers just about
everything mentioned so far in this thread, including guard bits. Note it
also mentions they are a hardware implementation - ie not "some software
technique you can just use".
It also mentions the necessity and inevitability of approximation.
See also the section "Exactly Rounded Operations" which discusses guard
bits.
and the sections "Relative Error and Ulps", and "Guard Digits"
(b)
ab aa aa aa aa aa ea 3f = 0.83333333333333337
as I and others have mentioned this is the closest number to 25.0/30.0 which
is representable in binary/hex
So why can't it store or use 0.83333333333333330 ? (By your description, the
number you would prefer it to use)
(b.1 STORE:)
Well as I explained elsethread if you change the "ab" to "aa" ie zero the
last bit
you get :
aa aa aa aa aa aa ea 3f which is 0.83333333333333326
Oops this is less than 0.83333333333333330
so lets go back another bit
a9 aa aa aa aa aa ea 3f = 0.83333333333333315
and another
a8 aa aa aa aa aa ea 3f = 0.83333333333333304
If we can't get 0.83333333333333330
can we get 0.83333333333333300 ?
let's subtract another one bit.
a7 aa aa aa aa aa ea 3f = 0.83333333333333293
Oops we've gone too far again.
and so on.
(b.2 USE:)
What if I have in my program :
x = 0.83333333333333337;
y = 0.83333333333333326;
should the computer just drop or ignore the "7" or "26" as you have
requested it to do for your calculation?
then z = x-y = 0.0000000000000001 in my program
but = 0.0000000000000030 in yours
That would make the calculation inaccurate "330" minus "300" would be wrong
for my program if I am working to the LSBs.
I will repeat what I said at the beginning.
If your algorithm is sensitive to the inaccuracy of the LSB of floating
point numbers then you need to rethink / rewrite your algorithm.
I did not stress this point before, as I thought you merely didn't
understand about the limitations of floating point internal representation.
Les
For the record.
I am not a C++ wizard or expert by any means.
My primary language for 30 years has been Fortran. Before that Cobol and
some Assembler.
I access this newsgroup in order to learn about MFC and C++ techniques as I
am now having to maintain and develop software using these tools.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- References:
- This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: GT
- 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: GT
- Re: This calculation is just wrong / computer can't count!
- From: Les
- Re: This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: Les
- This calculation is just wrong / computer can't count!
- 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
|