Author goodger
Recipients goodger
Date 2008-01-24.16:14:48
SpamBayes Score 0.0712245
Marked as misclassified No
Message-id <1201191290.86.0.944658382949.issue1924@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008-01-24 16:14:51goodgersetspambayes_score: 0.0712245 -> 0.0712245
recipients: + goodger
2008-01-24 16:14:50goodgersetspambayes_score: 0.0712245 -> 0.0712245
messageid: <1201191290.86.0.944658382949.issue1924@psf.upfronthosting.co.za>
2008-01-24 16:14:49goodgerlinkissue1924 messages
2008-01-24 16:14:48goodgercreate