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.
Created on 2011年02月07日 17:45 by arigo, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue11144.patch | mark.dickinson, 2011年02月09日 20:40 | review | ||
| Messages (7) | |||
|---|---|---|---|
| msg128143 - (view) | Author: Armin Rigo (arigo) * (Python committer) | Date: 2011年02月07日 17:45 | |
On 32 bits, there is no reason to get a 'long' here: >>> int(float(sys.maxint)) 2147483647L >>> int(int(float(sys.maxint))) 2147483647 >>> int(float(-sys.maxint-1)) -2147483648L >>> int(int(float(-sys.maxint-1))) -2147483648 On 64 bits, it's another story because floats cannot store 64 bits of precision. However, -sys.maxint-1 can still be represented exactly in a float, and the same issue occurs: >>> int(float(-sys.maxint-1)) -9223372036854775808L >>> int(int(float(-sys.maxint-1))) -9223372036854775808 |
|||
| msg128156 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2011年02月07日 21:15 | |
I'm not sure whether this is a bug, though. So I'd be skeptical that it should be changed in 2.x, even if the cause was identified. |
|||
| msg128167 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2011年02月08日 08:23 | |
I'd call this a bug, albeit a minor one. The documentation for 'int' says: "If the argument is outside the integer range a long object will be returned instead." ... which certainly suggests (without actually formally implying) that an int object should be returned if the argument is within the integer range. |
|||
| msg128189 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2011年02月08日 20:16 | |
> I'd call this a bug, albeit a minor one. The documentation for 'int' says: > > "If the argument is outside the integer range a long object will be returned instead." Ah ok. I agree it's a bug, then. |
|||
| msg128237 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2011年02月09日 20:40 | |
This turns out to be a one-line fix (modulo comments and tests); see attached patch. The new code depends on the assumption that C longs are represented using two's complement, but note that this assumption is (a) already present elsewhere in the Python core (e.g., in the definition of bitwise operations for ints), and (b) universally true in practice (as far as I'm aware). For theoretical completeness, it would be easy to write a different test for ones' complement and sign-magnitude machines, but in practice that seems pointless, and given the near-impossibility of testing that code, I left it out. |
|||
| msg128240 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2011年02月09日 20:52 | |
Very smart! |
|||
| msg132234 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2011年03月26日 12:30 | |
New changeset e1ebec2446cd by Mark Dickinson in branch '2.7': Issue #11144: Fix corner cases where float-to-int conversion unnecessarily returned a long. http://hg.python.org/cpython/rev/e1ebec2446cd |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:12 | admin | set | github: 55353 |
| 2011年03月26日 12:31:42 | mark.dickinson | set | status: open -> closed type: behavior stage: resolved resolution: fixed assignee: mark.dickinson |
| 2011年03月26日 12:30:18 | python-dev | set | nosy:
+ python-dev messages: + msg132234 |
| 2011年02月09日 20:52:24 | loewis | set | messages: + msg128240 |
| 2011年02月09日 20:40:08 | mark.dickinson | set | files:
+ issue11144.patch messages: + msg128237 keywords: + patch |
| 2011年02月08日 20:16:27 | loewis | set | messages: + msg128189 |
| 2011年02月08日 08:23:42 | mark.dickinson | set | messages: + msg128167 |
| 2011年02月08日 07:51:22 | mark.dickinson | set | nosy:
+ mark.dickinson |
| 2011年02月07日 21:15:52 | loewis | set | nosy:
+ loewis messages: + msg128156 |
| 2011年02月07日 17:45:54 | arigo | create | |