[FRPythoneers] I must be sitting too close to the monitor.

Ben Harding blh at hydrosphere.com
Thu Jan 13 09:45:21 MST 2005


What we call floating point numbers are a mapping of a continuous number 
space (real numbers) into a discrete number space (integers.)  There are 
holes in this map and some real numbers cannot be represented exactly.  
The internal representation used by the machine or software does it's 
best, but can't be perfect.

I bet there are others on this list that really know about this, and I 
would be interested in learning more about the floating point 
representation in general and that used by Python.

Ben

ccollier at viawest.net wrote:

>There is definitely something odd occuring.  First, note that it works if 
>you use integers (say 5 and 1).  Also, note that it works if you start 
>with change = 0.02.
>
>There is some interesting typing(?) occuring.  Here's a slightly modified 
>version:
>
>host$ cat test.py 
>change = 0.05
>while change >= 0.01:
>    print "a:", repr(change)
>    change = change - 0.01 
>    print "b:", (change)
>    print
>
>
>And the output with python 2.3:
>
>host$ python ./test.py 
>a: 0.050000000000000003
>b: 0.04
>
>a: 0.040000000000000001
>b: 0.03
>
>a: 0.029999999999999999
>b: 0.02
>
>a: 0.019999999999999997
>b: 0.01
>
>
>Anyone with some insight here?
>
>c
>
>
>On Wed, 12 Jan 2005, Scott Durkin wrote:
>
>  
>
>>Hi,
>>
>>My apologies for posing a VERY low-level user question . . .
>>
>>I use (well, try to anyway) Python in a junior high class I teach.  
>>I have a simple script and very dumb question . . . 
>>
>>SCRIPT:
>>
>>change = 0.05
>>while change >= 0.01:
>>    print change
>>    change = change - 0.01 
>>
>>OUTPUT:
>>
>>0.05
>>0.04
>>0.03
>>0.02
>>
>>QUESTION:
>>
>>Why doesn't "0.01" appear in the output?!?!?!
>>
>>Thank you for any help you could give me!
>>
>>Scott Durkin
>>
>>__________________________________________________________________________
>>    _____        ___     __   __   
>>   /____/ \     /_ /|   /_/| /_/| Scott Durkin - sdurkin at psdschools.org
>>  |  __ \ /|    | | |  | |__| | |
>>  | |__) |/  /|_| | |  |  __  | |           Computer Science
>>  |  ___/   ||__| | |  | | || | |         Preston Junior High
>>  |_|/      |_____|/   |_|/ |_|/                                         
>>                                  http://staffweb.psdschools.org/sdurkin
>>             2004-05                           970.419.7358
>>
>>_______________________________________________
>>This message sent by the FRPythoneers mailing list.
>>Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
>>URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
>>
>>    
>>
>
>_______________________________________________
>This message sent by the FRPythoneers mailing list.
>Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
>URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
>  
>




More information about the FRPythoneers mailing list