[Python-Dev] Unary minus bug

Neal Norwitz nnorwitz at gmail.com
Mon Jul 10 00:02:06 CEST 2006


Do we care about this (after your checkin and with my fix to make
32-63 bit values ints rather than longs):

# 64 bit box
>>> minint = str(-sys.maxint - 1)
>>> minint
'-9223372036854775808'
>>> eval(minint)
-9223372036854775808
>>> eval('-(%s)' % minint[1:])
-9223372036854775808L

n
--
On 7/9/06, Neil Schemenauer <nas at arctrix.com> wrote:
> The bug was reported by Armin in SF #1333982:
>
>     the literal -2147483648 (i.e. the value of -sys.maxint-1) gives
>     a long in 2.5, but an int in <= 2.4.
>
> I have a fix but I wonder if it's the right thing to do.  I suppose
> returning a long has the chance of breaking someone code.  Here's
> the test we currently have for a related case:
>
>     [...]
>     # 32-bit machine
>     all_one_bits = '0xffffffff'
>     self.assertEqual(eval(all_one_bits), 4294967295L)
>     self.assertEqual(eval("-" + all_one_bits), -4294967295L)
>
> I guess I would add self.assertTrue(isinstance(eval("-2147483648"), int))
> to that set of tests.
>
>   Neil
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/nnorwitz%40gmail.com
>


More information about the Python-Dev mailing list