Floating point precision nuances.
Posted
by user247077
on Stack Overflow
See other posts from Stack Overflow
or by user247077
Published on 2010-06-15T18:38:15Z
Indexed on
2010/06/15
18:42 UTC
Read the original article
Hit count: 217
c
|floating-point
Hi, I found this code in NVIDIA's cuda SDK samples.
void computeGold( float* reference, float* idata, const unsigned int len)
{
reference[0] = 0;
double total_sum = 0;
unsigned int i;
for( i = 1; i < len; ++i)
{
total_sum += idata[i-1];
reference[i] = idata[i-1] + reference[i-1];
}
// Here it should be okay to use != because we have integer values
// in a range where float can be exactly represented
if (total_sum != reference[i-1])
printf("Warning: exceeding single-precision accuracy. Scan will be inaccurate.\n");
}
(C) Nvidia Corp
Can somebody please tell me a case where the warning would be printed, and most importantly, why. Thank you very much.
© Stack Overflow or respective owner