Re: This calculation is just wrong / computer can't count!
- From: "Les" <l.neilson@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 5 Oct 2007 09:43:48 +0100
"GT" <ContactGT_remove_@xxxxxxxxxxx> wrote in message
news:0057a9e0$0$2887$c3e8da3@xxxxxxxxxxxxxxxxxxxx
Why is everyone having a go at me?
I apologise if you felt that I was having a go at you.
As I said, many people (myself included in the past) have struggled to
understand the cause of this problem which is due to the way floating point
numbers are stored in their internal binary representation.
This is the concept I and others have been trying to get across.
If I may show you an example from Another Language (but the principle is the
same)
(From Dave Eklund, Compaq Fortran Engineering)
"Consider 5.0 divided by powers of 10.:
do i = 1,10
x = 5.0/(10.**i)
type 1, x, x
1 format (1x, f40.30, 1x, b)
enddo
which produces in decimal and binary :
0.500000000000000000000000000000 111111000000000000000000000000
0.050000000745058059692382812500 111101010011001100110011001101
0.004999999888241291046142578125 111011101000111101011100001010
0.000500000023748725652694702148 111010000000110001001001101111
0.000049999998736893758177757263 111000010100011011011100010111
0.000004999999873689375817775726 110110101001111100010110101100
0.000000499999998737621353939176 110101000001100011011110111101
0.000000050000000584304871154018 110011010101101011111110010101
0.000000004999999969612645145389 110001101010111100110001110111
0.000000000499999985859034268287 110000000010010111000001011111
Only that first one is EXACT! Notice that the others,
while "close" to .05, .005, .0005. etc. are not EXACTLY .05, .005, .0005
etc. Some are a little bigger, some smaller (popularly called "nines
disease"). In fact, with the exception of 0.500, all the others CANNOT be
exactly represented as sums of powers of 2!"
"SUMS OF POWERS OF 2" That is the key to understanding computer floating
point math.
Les
.
- References:
- This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: AliR \(VC++ MVP\)
- Re: This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: Luke alcatel
- Re: This calculation is just wrong / computer can't count!
- From: GT
- 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
|
Loading