[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2017-03-07 Thread STINNER Victor
STINNER Victor added the comment: If you open the can of worms, other features will be requested like uint32+uint32 which would silently overflow. IMHO it would be better to have a package (on PyPI) providing integers of fixed size implementing two's complement arithmetic: int8, uint16, etc.

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2017-03-07 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- resolution: -> rejected stage: needs patch -> resolved status: pending -> closed ___ Python tracker

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2015-10-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I'm for closing this issue. This is not the common operation. -- nosy: +serhiy.storchaka status: open -> pending ___ Python tracker

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-06 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Instead of requiring bit_length(), couldn't you simply compare self to 2**(bits-1) (for to_unsigned) and 2**bits (for to_signed)? -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-06 Thread Mark Dickinson
Changes by Mark Dickinson dicki...@gmail.com: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13535 ___ ___

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-06 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: The 'self.bit_length() = bits' condition for to_unsigned doesn't look right to me. E.g., if bits == 32, I'd expect the acceptable range of values to be range(-2**31, 2**31)---i.e., including -2**31, but excluding 2**31. But the ValueError

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-06 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: On the feature request itself, I have to say that I'm unconvinced. Doing x % (2**32) seems good enough to me, in situations where you don't need the bounds checking. (And it's not clear to me that needing the bounds checks is the more

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-06 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: On the feature request itself, I have to say that I'm unconvinced. Doing x % (2**32) seems good enough to me, in situations where you don't need the bounds checking. Ah, I didn't know that modulo worked for that. Nice trick. --

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-06 Thread STINNER Victor
Changes by STINNER Victor victor.stin...@haypocalc.com: -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13535 ___ ___

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-05 Thread Nick Coghlan
New submission from Nick Coghlan ncogh...@gmail.com: This RFE proposes two new methods to_signed and to_unsigned on 'int' objects and on the numbers.Integral ABC. Semantics (and number.Integral implementation): def to_unsigned(self, bits): Convert this integer to its unsigned two's

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-05 Thread Eric V. Smith
Changes by Eric V. Smith e...@trueblade.com: -- nosy: +eric.smith ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13535 ___ ___ Python-bugs-list

[issue13535] Improved two's complement arithmetic support: to_signed() and to_unsigned()

2011-12-05 Thread Chris Rebert
Changes by Chris Rebert pyb...@rebertia.com: -- nosy: +cvrebert ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13535 ___ ___ Python-bugs-list