[Python-Dev] trunc()

Guido van Rossum guido at python.org
Sun Jan 27 19:33:06 CET 2008


On Jan 27, 2008 9:26 AM, Andrea Griffini <agriff at tin.it> wrote:
> On Jan 27, 2008 5:43 PM, Guido van Rossum <guido at python.org> wrote:
>
> > - Deprecating int(<float>) is pretty radical, I think it would have to
> > happen in the distant future. OR not at all. I'm at best +0 on this,
> > more like exactly 0. I realize that in practice this kills the idea.
> > The "purist" argument for it would have worked better if it was made
> > 18 years ago.
>
> Also what happens with "%i" % 3.14 ? We incidentally found a problem
> with a script using python 2.5 because apparently the "%" formatting
> operator doesn't use "int()" for doing the conversion (to be more specific
> if the float is too large for a 32-bit integer then the format operator chokes
> while the int() operator returns a long).

That's quite a separate issue. Please ses http://bugs.python.org/issue1742669.

> Anyway I want just to say that if "implicit" conversion from float
> to integer goes away then what happens to formatting conversion ?
> Removing that too IMO would break a lot of code and it's IMO very
> difficult to help fixing that.

The formatting code could assign specific meanings. I suspect though
that it was never meant to be possible to use %d with a float -- it
just is one of the artifacts of using implicit conversion, and one not
well-thought through. Note:

>>> "%.0f" % 3.9999999999
'4'
>>> "%d" % 3.9999999999
'3'
>>>

I think the latter is wrong and confusing.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list