On May 21, 5:45 pm, norseman <norse...@hughes.net> wrote: > seanm...@gmail.com wrote: > > The explaination in my introductory Python book is not very > > satisfying, and I am hoping someone can explain the following to me: > > >>>> 4 / 5.0 > > 0.80000000000000004 > > > 4 / 5.0 is 0.8. No more, no less. So what's up with that 4 at the end. > > It bothers me. > > ====================================== > > Machine architecture, actual implementation of logic on the chip and > what the compiler maker did all add up to creating rounding errors. I > have read where python, if left to its own, will output everything it > computed. I guess the idea is to show > 1) python's accuracy and > 2) what was left over > so the picky people can have something to gnaw on.
If you want to be picky, the exact value is 0.8000000000000000444089209850062616169452667236328125 (i.e., 3602879701896397/2**52). Python's repr function rounds numbers to 17 significant digits. This is the minimum that ensures that float(repr (x)) == x for all x (using IEEE 754 double precision). > Astrophysics, Astronomers and like kind may have wants of such. > If you work much in finite math you may want to test the combo to see if > it will allow the accuracy you need. Or do you need to change machines? The error in this example is roughly equivalent to the width of a red blood cell compared to the distance between Earth and the sun. There are very few applications that need more accuracy than that. -- http://mail.python.org/mailman/listinfo/python-list