msgpack-perl icon indicating copy to clipboard operation
msgpack-perl copied to clipboard

Support IEEE 754

Open akotlar opened this issue 9 years ago • 3 comments

Single precision floats defined in msgpack spec, doesn't seem to be implemented here, except during decoding stage.

This would save a significant amount of data for our team ~40% of ~80G per database.

akotlar avatar Jun 23 '16 23:06 akotlar

Perl support only double type(NV) for floating point number. We can have float value as pointer type but it requires much bytes(float + pointer) than double.

syohex avatar Jun 24 '16 09:06 syohex

Perl has the ability to pack / unpack 32 bit floats. We don't particularly care about whether perl will store a single precision float as double precision, what we care about is that msgpack doesn't use up 44% more space to store a single precision float. Also, message pack's goal is interoperability, else we could just pack / unpack in perl for every type and save the overhead of encoding the msgpack schema.

You support unpacking single precision floats in you PP package. I propose we add packing support for the same.

Even in the pure perl implementation it would be trivial to check whether a value fits in 32 bits, right (partial implementation):

if( unpack('f', pack('f', $num) ) == $num) { pack('f', $num) } else { pack('d', $num) }

I'd be happy to submit a pull request for the pure perl version.

If the runtime packing cost seems high, why don't we offer it as an option, much like utf8, prefer_integer, or your big int support.

akotlar avatar Jun 24 '16 16:06 akotlar

Any chance you could take another look at this? Treating all floats as doubles means that our database is substantially larger than needed.

akotlar avatar Sep 26 '17 22:09 akotlar