X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbinfloat.h;h=e50b3204ce974e992ca3cb52f5089456d8b16b39;hb=708ef339d3e4d3661c8b3a75e3b01bafbed0f568;hp=2c74441ad333888f1d47f98b1c3e449b40f98f6f;hpb=0d925901d1446de6fe76616b9b2e731d7702571e;p=libs%2Fdatafile.git diff --git a/source/binfloat.h b/source/binfloat.h index 2c74441..e50b320 100644 --- a/source/binfloat.h +++ b/source/binfloat.h @@ -29,9 +29,6 @@ struct BinFloat template struct MatchingInt; - template - union Conversion; - bool sign; bool infinity; int exponent; @@ -54,27 +51,21 @@ struct BinFloat::MatchingInt { typedef std::uint32_t Type; }; template<> struct BinFloat::MatchingInt { typedef std::uint64_t Type; }; -template -union BinFloat::Conversion -{ - T f; - typename MatchingInt::Type i; -}; - template inline BinFloat BinFloat::explode_iec559(T v) { - Conversion c; - c.f = v; - return explode(c.i, sizeof(T)*CHAR_BIT); + typename MatchingInt::Type i; + memcpy(&v, &i, sizeof(T)); + return explode(i, sizeof(T)*CHAR_BIT); } template inline T BinFloat::compose_iec559() { - Conversion c; - c.i = compose(sizeof(T)*CHAR_BIT); - return c.f; + typename MatchingInt::Type i = compose(sizeof(T)*CHAR_BIT); + T v; + memcpy(&v, &i, sizeof(T)); + return v; } } // namespace DataFile