PiRSquared17 / winpython

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

Spurious sum() Overflow on WinPython 3.3.2 64bit, Windows 8.1 64bit #100

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
On WinPython 3.3.2 64bit, solving the Euler Problem #10, the two functions

def prob10():  return int(sum(list(map(float,[i for i in primes() if 
i<2000000]))))     >>> 142913828922      

def prob10i(): return sum([i for i in primes() if i<2000000])
>>> 1179908154

yield DIFFERENT results. This is the primes() generator: 
def no_primes(): return {j for i in range(2,5000) for j in range(i*2, 
10000000,i)} 
def primes(): return [i for i in range(2,10000000) if i not in no_primes()]

If you convert them to float before summing, the result is correct.

If you just sum them, the result is less than 1% of the correct result.

This looks very much like an integer OVERFLOW in sum().  Is there effectively 
some kind of sys.maxint [which does not exist in Python3]?

Original issue reported on code.google.com by register...@yahoo.com on 23 Jan 2014 at 9:45

GoogleCodeExporter commented 9 years ago
I ended up facing the exact same issue with my code for this problem. 
I didn't realize that it was specific to winpython before, but I just tested 
with other scientific distrib and I cannot replicate the issue.

Anybody has find a solution? (or at least an explanation?)

Original comment by Bla...@gmail.com on 12 Apr 2014 at 2:45