On 6/20/05, Keith Dart <[EMAIL PROTECTED]> wrote: > On Mon, 20 Jun 2005, Guido van Rossum wrote: [...] > > By far the easiest way to do arithmetic mod 2**32 is to just add "& > > 0xFFFFFFFF" to the end of your expression. For example, simulating the > > effect of multiplying an unsigned long by 3 would be x = (x * 3) & > > 0xFFFFFFFF. > > But then I wouldn't know if it overflowed 32 bits.
Huh? C unsigned ints don't flag overflow either -- they perform perfect arithmetic mod 2**32. > In my usage, the > integer will be translated to an unsigned (32 bit) integer in another > system (SNMP). I want to know if it will fit, and I want to know early if > there will be a problem, rather than later (at conversion time). So check if it is >= 2**32 (or < 0, of course). > One of the "selling points" of Python in previous versions was that you > would get an OverFlowError on overflow, where other languages did not > (they overflowed silently). So I subclassed long in 2.3, to get the same > overflow exception: > ... > Again, because I want to catch the error early, before conversion to the > external type. This is a very specialized application. Your best approach is to check for overflow before passing into the external API -- ideally the wrappers for that API should do so. > > If there is a problem with ioctl() not taking long ints, that would be > > a bug in ioctl, not a lacking data type or a problem with long ints. > > That must be it, then. Shall I file a bug somewhere? SourceForge. (python.org/dev for more info) -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com