not a big deal or anything, but, curiously:

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Dec 13 01:49:50 EST 2006


At Wednesday 13/12/2006 03:14, Simon Schuster wrote:

>gc = float(count(cds, 'g') + count(cds, 'c'))/ len(cds)
>
>which should yield: 0.54460093896713613..
>
>but when I ran it I got: 0.544600938967
>
>looking now I see it's truncating after a certain number of decimal
>places. any ideas why?

Floating point numbers have finite precision so at *some* point the 
digits have to stop. The print statement uses str() to convert its 
arguments, and for a Python float that uses 12 digits. You could use 
repr() instead and get 17 digits:

 >>> print repr(gc)
0.54460093896713613

Read the Appendix B in the Python Tutorial for more info. Or look for 
"David Goldberg. What every computer scientist should know about 
floating-point arithmetic. ACM Computing Surveys, 23(1):5--48, March 1991."


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar



More information about the Python-list mailing list