When the total so far reaches a certain point it is much larger than the individual values being added on.
The added on value need to be be adjusted to the same floating point exponent as the sum so far.
This means moving the digits down and some fall of the end, giving an inaccurate representation.
Using doubles will help fix this because they have much more digits and so will not lose accuracy so quickly.
Ziv Mhabary, please don't remove your first post. If you are not allowed to ask for questions, don't ask!
Here is the post in case someone is interested
Hello,
I have the next code which calculate mean of an matrix.
all the values in the matrix are 17. from some reason, after some iterations, its start to add 16 to the sum parmeters. Any idea way?
The code:
float findAvg(float* ptr,int step){
float sum=0;
for (int r=0;r<1024;r++)
for(int c=0;c<2048;c++)
sum+=ptr[r*step+c];
return sum/(1024*2048);
}
Hello,
I have the next code which calculate mean of an matrix.
all the values in the matrix are 17. from some reason, after some iterations, its start to add 16 to the sum parmeters. Any idea way?
The code:
float findAvg(float* ptr,int step){
float sum=0;
for (int r=0;r<1024;r++)
for(int c=0;c<2048;c++)
sum+=ptr[r*step+c];
return sum/(1024*2048);
}