Commit 2b7ef426 authored by Mathieu Malaterre's avatar Mathieu Malaterre
Browse files

BUG: in Floor function, use union to avoid violation of aliasing rules

parent 62ddcece
......@@ -191,7 +191,7 @@ public:
double out[3]);
// Description:
// Mutltiply one 3x3 matrix by another according to C = AB.
// Multiply one 3x3 matrix by another according to C = AB.
static void Multiply3x3(const float A[3][3], const float B[3][3],
float C[3][3]);
static void Multiply3x3(const double A[3][3], const double B[3][3],
......@@ -570,15 +570,15 @@ private:
inline int vtkMath::Floor(double x)
{
#if defined i386 || defined _M_IX86
double tempval;
union { int i[2]; double d; } u;
// use 52-bit precision of IEEE double to round (x - 0.25) to
// the nearest multiple of 0.5, according to prevailing rounding
// mode which is IEEE round-to-nearest,even
tempval = (x - 0.25) + 3377699720527872.0; // (2**51)*1.5
u.d = (x - 0.25) + 3377699720527872.0; // (2**51)*1.5
// extract mantissa, use shift to divide by 2 and hence get rid
// of the bit that gets messed up because the FPU uses
// round-to-nearest,even mode instead of round-to-nearest,+infinity
return ((int*)&tempval)[0] >> 1;
return u.i[0] >> 1;
#else
return (int)floor(x);
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment