I have the following code, where the assertion fails. Can anyone explain me why?
double *E = (double *) malloc(sizeof(double) * voxelSpaceSize);
double *E_new = (double *) malloc(sizeof(double) * voxelSpaceSize);
// ...some manipulations inside E and E_new, the memory locations do not change though
...
memcpy(E, E_new, sizeof(double) * voxelSpaceSize);
for (int i=0; i<voxelSpaceSize; i++) {
assert(E[i] == E_new[i]);
}
By definition, the special floating-point value
NaNis not equal to itself:NaN == NaNreturns false. So now I’m betting the value at the unequal index isNaN. You may want to print out the value at the index where the value’s not equal to itself, rather than usingassert.