cy99 / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

error: integer constant is too large for "long" type #30

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Apologies in advance if this is my ignorance!  And thank you for producing
such a great product.

I came across this problem trying to solve problem 234 of the euler
project.  The issue seems to be one of converting the python "long" type
into a C++ type that will handle very large integers.

What steps will reproduce the problem?

I created the following code in python:
************************************************
from time import time

def isPrime(n):
    """tests the primality of n the hard way (instead of sympy's
    isprime)"""
    if n==1:
        return 0
    elif n<=3:
        return 1
    if n%2==0:
        return 0
    for i in range(3,int(n**(0.5))+1,2):
        if n%i==0:
            return 0
    return 1

startTime=time()
myN= 1000000000L  #probably need SWIG/shed skin to do this...

i=0L
myPs=[2L]
for i in range(3,int(myN**0.5)+1,2):
    if isPrime(i):
        myPs.append(i)
i+=2
while not isPrime(i):
    i+=2
myPs.append(i)
print "Primes generated up to",max(myPs)

mySD=0L
i=0L
k=0L
lps=0L
ups=0L
while 1:
    lps=myPs[i]
    ups=myPs[i+1]
    for k in xrange(lps**2+1,ups**2):
        if k>myN: break
        divs=0
        if k%lps==0: divs+=1
        if k%ups==0: divs+=1
        if divs==1: mySD+=k
    if k>myN: break
    i+=1

print "the sum of semidivs not exceeding",myN,"is",mySD

finishTime=time()
print "time taken: %f" %(finishTime-startTime)
*****************************************************

For myN=1000000L it seems to work fine (answer agrees with python, and runs
in a tenth of the time)

For myN=10000000L it produces a negative answer for a sum of large positive
numbers, without producing any errors or warnings, suggesting that the
integer has "ticked over" to a negative number.  Similar results up to
myN=1000000000L.  The expected output is a large positive integer.

For myN=999966663333L it produces the error in the title.

What version of the product are you using? On what operating system?
I'm running Skin Shed 0.1 (downloaded 3 Mar 2009) with Windows XP.

Please provide any additional information below.

many thanks

Original issue reported on code.google.com by glenton....@gmail.com on 3 Mar 2009 at 7:34

GoogleCodeExporter commented 8 years ago
hi glenton,

thanks for reporting this problem. unfortunately, arbitrary-size arithmetic is 
not
supported at the moment. Python ints are currently mapped to C++ ints, which are
usually 32-bit and will overflow at about 2**31. please see the tutorial for an
overview of other limitations :)

Original comment by mark.duf...@gmail.com on 3 Mar 2009 at 11:30