jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

Processing is probably causing an integer overflow while Jupyter does not. #268

Closed Marcus1000 closed 5 years ago

Marcus1000 commented 5 years ago

During my implementation of a visual illustration of Pascal's triangle with Python Mode for Processing for MAC OS X I experienced the following somewhat strange behaviour of Processing compared to e.g. Jupyter.

One of the necessary steps in my project is the calculation of the binomial coefficients in each row of the triangle. I chose to do it in a recursive way instead of calculating factorials. My code works well in Jupyter, but produces different outcomes in Processing.

rows = 301

pascal=[[1], [1,1]]
for i in range (rows):
    last_row = pascal[len(pascal)-1]
    next_row = [1] +[last_row[i]+last_row[i+1] for i in range(len(last_row)) if i < len(last_row)-1] +[1]
    pascal.append(next_row)

print (pascal[35][16])

The problems begin in row 35 of the triangle (countig starts from 0). The 16th element in this row should be 4059928950 but Processing calculates -235038346. And from then on, the calculations in Processing seem to be often wrong. I guess it is an integer overflow problem, but I am not sure.

jdf commented 5 years ago

Yep, we don't support arbitrary numerics; it's just Java integers.