I try to fill dynamically allocated arrays with numbers that are calculated in the program. One of these arrays is very large (1000 x 900 x 3).
If I fill it with doubles, the program output will occasionally be reasonable, but on successive runs of the same code different outputs are created. In most cases these become absurdly huge (10e+74 or 10e+228). However, if I use floats for that specific array, everything is fine - numbers are reasonable and reproducible.
Any thoughts why this happens? Even more important: Can I just keep floating numbers or may there be a larger issue that needs further investigation
Edit:
This calculated the entries of the large array:
T[it+1][ix][iy] = T[it][ix][iy] + ((1/(dx*dx))*(T[it][ix+1][iy] - 2*T[it][ix][iy] + T[it][ix-1][iy]) + (1/(dy*dy))*(T[it][ix][iy+1] - 2*T[it][ix][iy] + T[it][ix][iy-1]) + M_SQRT2*cos(iy*dy)- Pe*((1/((2*dx)))*vx[it][ix][iy]*(T[it][ix+1][iy]-T[it][ix-1][iy]) + (1/(2*dy))*vy[it][ix][iy]*(T[it][ix][iy+1] - T[it][ix][iy-1])))*dt;
I don't want to post the whole code, it is fairy large. If you would like to see anything else, please let me know.
Edit 2:
After rewriting the program with 3D-vectors, which did not change anything. I eventually found out, that I used an even number for the array sizes. Changing it (and the intervals dx and dy) to an odd number fixes the issue. Any thoughts on that phenomenon?