4 hundred quadrillonth?

Carl Banks pavlovevidence at gmail.com
Thu May 21 17:53:38 EDT 2009


On May 21, 2:05 pm, seanm... at 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.

That would depend on how you define the numbers and division.

What you say is correct for real numbers and field division.  It's not
true for the types of numbers Python uses, which are not real numbers.

Python numbers are floating point numbers, defined (approximately) by
IEEE 754, and they behave similar to but not exactly the same as real
numbers.  There will always be small round-off errors, and there is
nothing you can do about it except to understand it.


> It bothers me.

Oh well.

You can try Rational numbers if you want, I think they were added in
Python 2.6.  But if you're not careful the divisors can get
ridiculously large.


Carl Banks



More information about the Python-list mailing list