For some while I have used code like this to extract efficiently the bit pattern of a double as an int64:
inline
int64 rawDouble(double aDouble)
{
union Union {
Union(double aDouble) : fDouble(aDouble) {}
int64 bits() { return fInt64; }
double fDouble;
int64 fInt64;
};
return Union(aDouble).bits();
}
(Clearly there is an entirely analogous pattern for extracting the bit pattern of a single as an int32.)
I like this trick because the x86's SEE instructions (and it analogous in other instruction sets) allow individual register locations to be interpreted as integer or floating point on an instruction by instruction basis.
It has been pointed out to me that C++11 and later regard this an UB.
If I cannot use this trick what C++ sanctioned approach can I take?