[Tutor] Range limited?

fleet@teachout.org fleet@teachout.org
Mon, 30 Jul 2001 13:12:36 -0400 (EDT)


On Mon, 30 Jul 2001, Danny Yoo wrote:

> > PS:  Should the above be
> > "while long(i) < upper-bound-of-many-digit-number"?
> > Will "i" go flaky after 16 digits or is it sufficient that only one number
> > be long?
>
> Theoretically, it shouldn't go flaky because 'long' integers are of
> unlimited length.  Let's see, how many atoms are there in the universe?

If the expression is 'while i < upper-bound-of-many-digit-number' (ie, i
is not long), then i appears to have an upper limit of 2147483647.

>>> i 2147483647
>>> i=i+1
Traceback (innermost last):
  File "<stdin>", line 1, in ?
OverflowError: integer addition

also tried:

>>> lower
2147483447L  #200 less than "i" above
>>> upper
2147483847L  #200 more than "i" above
>>> step
1
>>> for i in xrange(lower,upper,step):
    ...  print i
    ...
Traceback (innermost last):
  File "<stdin>", line 1, in ?
OverflowError: long int too long to convert
>>>

AND ...

while lower < upper:
   print lower
   lower=lower+1

[first 396 numbers deleted]
2147483644
2147483645
2147483646
2147483647
Traceback (innermost last):
  File "<stdin>", line 3, in ?
OverflowError: integer addition

So it looks to me like range and xrange both attempt to convert the long
arguments to integers and 2147483647 is the upper limit.

					- fleet -