From 6f0683bb4696b11ed9a3a60f925bf034745c60a7 Mon Sep 17 00:00:00 2001 From: Georg Fritze Date: Fri, 13 May 2022 13:04:17 +0200 Subject: [PATCH] pack double and float more size efficient --- include/msgpack/v1/pack.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/msgpack/v1/pack.hpp b/include/msgpack/v1/pack.hpp index 677c39fa..131c889b 100644 --- a/include/msgpack/v1/pack.hpp +++ b/include/msgpack/v1/pack.hpp @@ -1138,6 +1138,11 @@ inline packer& packer::pack_unsigned_long_long(unsigned long lon template inline packer& packer::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& packer::pack_float(float d) template inline packer& packer::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];