[Insight-users] Bug in itkBSplineInterpolationWeightFunction.txx
itkuser at yahoo.fr
itkuser at yahoo.fr
Fri Nov 18 11:42:54 EST 2005
I had already submitted this bug to the phpBugTracker a while ago, but it is
still there...
Fast floor function BSplineFloor(double x) in file
itkBSplineInterpolationWeightFunction.txx is not correct on x86 platform:
it casts an int pointer to a double pointer, which is forbidden by ISO C
standard (standard says that two different pointers may not point to the same
location, as a result when optimizing the BSplineFloor function, the
dereferencement and assignement of the pointer to double is optimized away).
The bug can be reproduced using gcc 3.4 with -O2 or -O3 flag on x86 platform,
with the simple test case:
inline int BSplineFloor(double x)
{
unsigned int hilo[2];
*((double *)hilo) = x + 103079215104.0; // (2**(52-16))*1.5
return (int)((hilo[1]<<16)|(hilo[0]>>16));
}
int main()
{
assert(BSplineFloor(0.5)==0);
return 0;
}
Replacing
unsigned int hilo[2];
*((double *)hilo) = x + 103079215104.0;
return (int)((hilo[1]<<16)|(hilo[0]>>16));
by
union { unsigned int hilo[2]; double d; } u;
u.d = x + 103079215104.0;
return (int)((u.hilo[1]<<16)|(u.hilo[0]>>16));
seems to fix the problem.
Could this bug be fixed for the next release?
Thanks,
nicolas
More information about the Insight-users
mailing list