Christopher A. Craig
com-nospam at ccraig.org
Fri Aug 3 19:51:09 CEST 2001
-----BEGIN PGP SIGNED MESSAGE-----
cstein at giftcertificates.com (Casey Stein) writes:
> Why is it converting my 66.6 to 66.599999999999994?
Because 66.6 is a binary floating point number, which must be
represented in as powers of two by the computer. Specifically (in
this case) 4686558362232422 * (2**-46).
Though this probably doesn't make much sense to you, it makes a great
deal of sense to the computer, which has to think of everything as
some power of 2. You think of 12 as 10+2 (1*(10**1)+2*(10**0)), but
your computer thinks of it as 8+4 (1*(2**3)+1*(2**2)).
There are other, more acuarate, ways to do this (such as representing
66.6 as 333/5), but they are all _much_ slower than using floats, so
Python currently uses floats (There are people who would like to
for more information.
Christopher A. Craig <com-nospam at ccraig.org>
"The world would be a better place if Larry Wall had been born in Iceland,
or any other country where the native language actually has syntax."
-- Peter da Silva (in alt.sysadmin.recovery)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt
-----END PGP SIGNATURE-----
More information about the Python-list