template<typename T>
struct MatchingInt;
- template<typename T>
- union Conversion;
-
bool sign;
bool infinity;
int exponent;
template<>
struct BinFloat::MatchingInt<double> { typedef std::uint64_t Type; };
-template<typename T>
-union BinFloat::Conversion
-{
- T f;
- typename MatchingInt<T>::Type i;
-};
-
template<typename T>
inline BinFloat BinFloat::explode_iec559(T v)
{
- Conversion<T> c;
- c.f = v;
- return explode(c.i, sizeof(T)*CHAR_BIT);
+ typename MatchingInt<T>::Type i;
+ memcpy(&v, &i, sizeof(T));
+ return explode(i, sizeof(T)*CHAR_BIT);
}
template<typename T>
inline T BinFloat::compose_iec559()
{
- Conversion<T> c;
- c.i = compose(sizeof(T)*CHAR_BIT);
- return c.f;
+ typename MatchingInt<T>::Type i = compose(sizeof(T)*CHAR_BIT);
+ T v;
+ memcpy(&v, &i, sizeof(T));
+ return v;
}
} // namespace DataFile