int * vals = (int*) malloc(100000000*sizeof(int)); for(int i=0; i<100000000; i++){ int val = ((float) rand()/RAND_MAX)*5; vals[i] = val; if(i%100000==0) srand(val); } float total = 0; for(int i=0; i<20000; i++){ for(int j=0; j<5000; j++){ float val = vals[i*5000+j]; total += val; } } //total = total*10; printf("Total is: %f Average: %f\n", total, total/100000000); free(vals);

I checked the vals array above where the total maxes out, and it still has positive values at those points. I also thought maybe it had to do with rand() seeding order so I added srand() now and then. At the end I can still multiple 'total' by 10 to increase it, as you'd expect a float to be able to increase arbitrarily. However inside the loops, once it reaches 64*1024*1024, it stops increasing. I also found that if once changed the 'val' loop to be of type float, then the max for total become 128*1024*1024.

Why is total maxing out inside the loop, despite being a floating point?