Precision Issue
Christopher A. Craig
com-nospam at ccraig.org
Fri Aug 3 13:51:09 EDT 2001
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
change that.)
See
http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.098.htp
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
iEYEARECAAYFAjtq5I0ACgkQjVztv3T8pztPPQCfR3dYm5BOihmM2VO5aym+taqa
0o4An06y1u06No7iV7t5vALl1zGTnYmf
=uys4
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list