[Tutor] Range limited?

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 30 Jul 2001 08:57:55 -0700 (PDT)


On Mon, 30 Jul 2001 fleet@teachout.org wrote:

> Thanks for the pointer to xrange.  I circumvented the problem by switching
> to "while i < [long(sqrt(target number))]: " I set a print command to
> print 'i' in multiples of 10,000.  About 10 hours later I had hit a
> billion (10 digits).  Hmmmm, 74 digits to go! :) I think not.
> 
> (Actually, I investigated primes a little and after finding that the
> 200,000th prime number is only 7 digits long, I pretty much decided I
> can't run with the big dogs - so I'll just stay on the porch!) :)
> 
> 				- fleet -
> 
> 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?


###
>>> atoms = "1" + ("0" * 68)
>>> atoms
'100000000000000000000000000000000000000000000000000000000000000000000'
>>> long(atoms)
100000000000000000000000000000000000000000000000000000000000000000000L
###

You should be fine with 16 digits.  *grin*



However, I think that Python doesn't automatically consider really large
integers as longs, so you might need to long()ify the
upper-bound-of-many-digit-number as well:

###
>>> 1000000000000000000000000000000000000000000000000
OverflowError: integer literal too large
###