summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0d92590)
The compiler should be able to optimize it away.
template<typename T>
struct MatchingInt;
template<typename T>
struct MatchingInt;
- template<typename T>
- union Conversion;
-
bool sign;
bool infinity;
int exponent;
bool sign;
bool infinity;
int exponent;
template<>
struct BinFloat::MatchingInt<double> { typedef std::uint64_t Type; };
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)
{
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()
{
}
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
}
} // namespace DataFile