Re: Conversion error



dada said:


Consider the following function...

130075000 / 1000000.0 is 130.075 - which we must try to store in
computer memory, which is made up of bits. Bits suggest a binary
representation. Representing the integer part (130) in binary is easy
enough - it's 10000010. But 0.075 is a touch harder:

0.1 = 1/2 = 0.5 - too large
0.01 = 1/4 = 0.25 - too large
0.001 = 1/8 = 0.125 - too large
0.0001 = 1/16 = 0.0625 - too small
0.00011 = 3/32 = 0.09375 - too large
0.000101 = 5/64 = 0.078125 - too large
0.0001001 = 9/128 = 0.0703125 - too small
0.00010011 = 19/256 = 0.07421875 - too small
0.000100111 = 39/512 = 0.076171875 - too large
0.0001001101 = 77/1024 = 0.0751953125 - too large
0.00010011001 = 153/2048 = 0.07470703125 - too small
0.000100110011 = 307/4096 = 0.074951171875 - too small
0.0001001100111 = 615/8192 = 0.0750732421875 - too large
0.00010011001101 = 1229/16384 = 0.07501220703125 - too large
0.000100110011001 = 2457/32768 = 0.074981689453125 - too small
0.0001001100110011 = 4915/65536 = 0.0749969482421875 - too small

How many bits do you think we will need before we get exactly 0.075?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.