This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: %i string format breaks for large floats (incomplete int conversion)
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.4, Python 2.3, Python 2.6, Python 2.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: facundobatista, goodger
Priority: normal Keywords:

Created on 2008-01-24 16:14 by goodger, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg61635 - (view) Author: David Goodger (goodger) (Python committer) Date: 2008-01-24 16:14
I ran across this bug in some legacy production code when numbers got high:

>>> '%i' % 2e9
'2000000000'
>>> '%i' % 3e9
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: int argument required

It looks like the float is being automatically converted to an int, but
floats > sys.maxint cause an error.  However,

>>> int(3e9)
3000000000L

So the implicit float-to-int conversion is imperfect; large floats are
not being converted to long ints.

Same error in Python 2.3 through 2.6a0 (as of 2007-12-28).

In Python 2.1.3 & 2.2.3 the error is "OverflowError: float too large to
convert".  The same error is triggered by int(3e9) though.

While it's arguably not-quite-sane to have code that triggers this
error, the inconsistency is what concerns me.
msg61637 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-01-24 16:23
Duplicates #1742669 (copied this text to there)
History
Date User Action Args
2022-04-11 14:56:30adminsetgithub: 46218
2008-01-24 16:23:17facundobatistasetstatus: open -> closed
resolution: duplicate
messages: + msg61637
nosy: + facundobatista
2008-01-24 16:14:49goodgercreate