Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%i string format breaks for large floats (incomplete int conversion) #46218

Closed
goodger opened this issue Jan 24, 2008 · 2 comments
Closed

%i string format breaks for large floats (incomplete int conversion) #46218

goodger opened this issue Jan 24, 2008 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@goodger
Copy link
Contributor

goodger commented Jan 24, 2008

BPO 1924
Nosy @goodger, @facundobatista

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-01-24.16:23:17.307>
created_at = <Date 2008-01-24.16:14:49.396>
labels = ['interpreter-core', 'type-bug']
title = '%i string format breaks for large floats (incomplete int conversion)'
updated_at = <Date 2008-01-24.16:23:17.299>
user = 'https://github.com/goodger'

bugs.python.org fields:

activity = <Date 2008-01-24.16:23:17.299>
actor = 'facundobatista'
assignee = 'none'
closed = True
closed_date = <Date 2008-01-24.16:23:17.307>
closer = 'facundobatista'
components = ['Interpreter Core']
creation = <Date 2008-01-24.16:14:49.396>
creator = 'goodger'
dependencies = []
files = []
hgrepos = []
issue_num = 1924
keywords = []
message_count = 2.0
messages = ['61635', '61637']
nosy_count = 2.0
nosy_names = ['goodger', 'facundobatista']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1924'
versions = ['Python 2.6', 'Python 2.5', 'Python 2.4', 'Python 2.3']

@goodger
Copy link
Contributor Author

goodger commented Jan 24, 2008

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.

@goodger goodger added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 24, 2008
@facundobatista
Copy link
Member

Duplicates bpo-1742669 (copied this text to there)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants