Description
I am trying to understand why I get unexpected values decoding 32-bit floating point values coming from my back-end.
This is true
decode(encode(59.48)) === 59.48
But looking at the intermediate value, the encoding is producing a 64-bit floating point representation [203, 64, 77, 189, 112, 163, 215, 10, 61]
.
So far, all is good. The problem starts when I post my raw data to my back-end and that does the serialization. That has been told the type up-front and encodes the input as a 32-bit floating point number -> [202, 66, 109, 235, 133]
. That should be fine, and when decoding on the back-end, I get the exact value back.
However, when decoding using this library like decode([202, 66, 109, 235, 133])
what I actually get is 59.47999954223633
.
I believe this is a bug because the library can safely round-trip floating point numbers without a loss of precision so it seems like there is an issue in the handling of the 32-bit msgpack representation of this number.