Skip to content

Commit 6f0683b

Browse files
committed
pack double and float more size efficient
1 parent 63511f2 commit 6f0683b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

include/msgpack/v1/pack.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,11 @@ inline packer<Stream>& packer<Stream>::pack_unsigned_long_long(unsigned long lon
11381138
template <typename Stream>
11391139
inline packer<Stream>& packer<Stream>::pack_float(float d)
11401140
{
1141+
if (d == int64_t(d))
1142+
{
1143+
pack_imp_int64(int64_t(d));
1144+
return *this;
1145+
}
11411146
union { float f; uint32_t i; } mem;
11421147
mem.f = d;
11431148
char buf[5];
@@ -1149,6 +1154,12 @@ inline packer<Stream>& packer<Stream>::pack_float(float d)
11491154
template <typename Stream>
11501155
inline packer<Stream>& packer<Stream>::pack_double(double d)
11511156
{
1157+
if (d == int64_t(d))
1158+
{
1159+
pack_imp_int64(int64_t(d));
1160+
return *this;
1161+
}
1162+
11521163
union { double f; uint64_t i; } mem;
11531164
mem.f = d;
11541165
char buf[9];

0 commit comments

Comments
 (0)