[Python-bugs-list] [ python-Bugs-434186 ] 0x80000000/2 != 0x80000000>>1

noreply@sourceforge.net noreply@sourceforge.net
Mon, 18 Jun 2001 09:28:11 -0700


Bugs item #434186, was updated on 2001-06-18 08:14
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=434186&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
>Priority: 7
Submitted By: Nobody/Anonymous (nobody)
>Assigned to: Tim Peters (tim_one)
Summary: 0x80000000/2 != 0x80000000>>1

Initial Comment:
[16:07:29 toby@ruislip-manor] $ python
Python 2.1 (#2, May 15 2001, 11:04:28) 
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more 
information.
>>> 0x80000000>>1
-1073741824
>>> 0x80000000/2
1073741824
>>> 0x80000000/-2
-1073741824
>>> 

Pretty much says it all.

the problem seems to be computing -xi in 
intobject.c:i_divmod causing an overflow.


----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2001-06-18 09:28

Message:
Logged In: YES 
user_id=31435

Very curious!  On Windows,

>>> 0x80000000 >> 1
-1073741824
>>> 0x80000000 / 2
-1073741824
>>> 0x80000000 / -2
1073741824
>>>

That is, it works as expected.  However, that appears to be 
an accident due to the way the MS compiler optimizes this.  
In a debug build, the Windows results match yours:

Python 2.2a0 (#16, Jun 18 2001, 11:17:03) [MSC 32 bit 
(Intel)] on win32
Type "copyright", "credits" or "license" for more 
information.
>>> 0x80000000 / 2
1073741824
[5509 refs]
>>> 0x80000000 / -2
-1073741824
[5509 refs]
>>>

Certainly agreed this is a bug, and boosted the priority.  
Until it's fixed, you won't see the problem if you use long 
ints instead.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=434186&group_id=5470