X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fbinfloat.h;h=2c74441ad333888f1d47f98b1c3e449b40f98f6f;hp=d16570fc057fa296a349f2b69bb167d68a960ceb;hb=0d925901d1446de6fe76616b9b2e731d7702571e;hpb=9c95942d24a92abea14bb9e11d33daae2d017321 diff --git a/source/binfloat.h b/source/binfloat.h index d16570f..2c74441 100644 --- a/source/binfloat.h +++ b/source/binfloat.h @@ -1,7 +1,9 @@ #ifndef MSP_DATAFILE_BINFLOAT_H_ #define MSP_DATAFILE_BINFLOAT_H_ -#include "type.h" +#include +#include +#include namespace Msp { namespace DataFile { @@ -25,38 +27,56 @@ struct BinFloat }; template - union Conversion - { - T f; - typename MatchingInt::UnsignedType i; - }; + struct MatchingInt; + + template + union Conversion; bool sign; bool infinity; int exponent; - UInt64 mantissa; + std::uint64_t mantissa; - static BinFloat explode(UInt64, const Bits &); + static BinFloat explode(std::uint64_t, const Bits &); template - static BinFloat explode_iec559(T v) - { - Conversion c; - c.f = v; - return explode(c.i, sizeof(T)*CHAR_BIT); - } + static BinFloat explode_iec559(T v); - UInt64 compose(const Bits &); + std::uint64_t compose(const Bits &); template - T compose_iec559() - { - Conversion c; - c.i = compose(sizeof(T)*CHAR_BIT); - return c.f; - } + T compose_iec559(); }; +template<> +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); +} + +template +inline T BinFloat::compose_iec559() +{ + Conversion c; + c.i = compose(sizeof(T)*CHAR_BIT); + return c.f; +} + } // namespace DataFile } // namespace Msp