[Tutor] Limiting variable size

Daniel Ehrenberg littledanehren at yahoo.com
Mon Jan 26 12:28:59 EST 2004


Scott wrote:
> Is there a way to set the maximum numeric value of a
> variable?  I want x
> to roll over if it gets to over four bytes.  I've
> got a little routine
> to *and*  them with "0xffffffff."  But seems like
> there's a better way!
> 
> Thanks guys!

I don't think there's a way to do it besides just
doing a mod like below:

x %= 4294967296 #four bytes

This will only work when you explicitly do this on a
value; it won't overflow automatically. Although ints
are limited in value, when they overflow they are
automatically converted to longs, which top out at
some very large, system-dependent value. The only way
I can think of changing the maximum value is to hack
Python itself.

Why do you want to do this, anyway?

Daniel Ehrenberg

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/



More information about the Tutor mailing list