Message71116
One possible fix would be to compute the absolute value
of n as an unsigned long. I *think* the following is
portable and avoids any undefined behaviour coming
from signed arithmetic overflow.
unsigned long absn;
if (n < 0)
absn = 1 + (unsigned long)(-1-n);
else
absn = (unsigned long)n;
Might this work?
Perhaps it would also be worth changing the tests
in test_int from e.g.
self.assertEqual((-a).numbits(), i+1)
to
self.assertEqual(int(-a).numbits(), i+1)
This would have caught the -LONG_MAX error. |
|
Date |
User |
Action |
Args |
2008-08-14 09:47:11 | mark.dickinson | set | recipients:
+ mark.dickinson, loewis, rhettinger, fredrikj |
2008-08-14 09:47:11 | mark.dickinson | set | messageid: <1218707231.58.0.459715716283.issue3439@psf.upfronthosting.co.za> |
2008-08-14 09:47:10 | mark.dickinson | link | issue3439 messages |
2008-08-14 09:47:10 | mark.dickinson | create | |
|