pack double and float more size efficient

This commit is contained in:
Georg Fritze 2022-05-13 13:04:17 +02:00
parent 63511f29db
commit 6f0683bb46

View File

@ -1138,6 +1138,11 @@ inline packer<Stream>& packer<Stream>::pack_unsigned_long_long(unsigned long lon
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_float(float d)
{
if (d == int64_t(d))
{
pack_imp_int64(int64_t(d));
return *this;
}
union { float f; uint32_t i; } mem;
mem.f = d;
char buf[5];
@ -1149,6 +1154,12 @@ inline packer<Stream>& packer<Stream>::pack_float(float d)
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_double(double d)
{
if (d == int64_t(d))
{
pack_imp_int64(int64_t(d));
return *this;
}
union { double f; uint64_t i; } mem;
mem.f = d;
char buf[9];