X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbinfloat.h;h=f6e6d1fb5b493a045022fefc7af2c1ecc2aec335;hb=d3c55a54b4c6ed0f740a87e5446e4054888bdcdf;hp=2c74441ad333888f1d47f98b1c3e449b40f98f6f;hpb=0d925901d1446de6fe76616b9b2e731d7702571e;p=libs%2Fdatafile.git diff --git a/source/binfloat.h b/source/binfloat.h index 2c74441..f6e6d1f 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(&i, &v, 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