Why Python 3?

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue Apr 22 02:03:32 EDT 2014


Chris Angelico wrote:
> As it
> is, we have the case that most lowish integers have equivalent floats
> (all integers within the range that most people use them), and beyond
> that, you have problems.

No, I don't. I'm not talking about representing ints using
floats, I'm talking about representing floats using ints.
*Every* possible integer-valued float value can be written
exactly as a Python int.

It doesn't matter that there are some ints that can't be
represented as floats, because when I'm writing an int literal
as a shorthand for a float, I'm not going to be using any of
those values -- or if I do, I'm willing to accept the
resulting loss of precision, because in my mind they're
*not* ints, they're floats.

> But
> would you rather have to deal with the problem straight away, or when
> your program is some day given a much bigger number to swallow, and it
> quietly rounds it off to the nearest multiple of 8?

I don't understand what problem you're imagining here.
Any program that needs to do exact calculations with integer
values should work with ints throughout and use // or
divmod() if it needs to do any division. Nothing will get
unexpectedly rounded off then.

-- 
Greg



More information about the Python-list mailing list