Closed SX91 closed 2 years ago
No, that's not okay. Let's fix it :).
Ok, turns out we use Double for ObjectDouble. Where do you see those lossy conversions?
Look at the MessagePack Float instance.
I'm looking at it - it looks fine to me. The MessagePack Float instance is something client code can use if they choose to use Float in their types. If client code uses Double, it will use the instance for Double, which does no conversions and generates msgpack double.
You shouldn't be looking at the MessagePack instances, since that's at a higher level. The decoding of msgpack doubles is done in Get.hs, in getDouble.
You shrink Double value to Float, that's not good. Float to Float is perfectly fine, Float to Double is perfectly fine, Double to Float is not fine at all. Some Float instace should not shrink ObjectDouble's Double to Float IMO.
So what should the Float instance do instead? Note that the Float instance defines fromObject :: Object -> m Float
.
Extract ObjectFloat's Float. Not ObjectDouble's Double and then shrinking it.
I don't understand what you mean, since what I understand makes no sense. Can you make a PR for this?
@iphydf I mean that this https://github.com/TokTok/hs-msgpack/blob/master/src/Data/MessagePack/Class.hs#L144 is not okay
What should it be doing instead?
Ignore ObjectFloat
constructor (remove that line).
Ok, make a PR that either fixes it or introduces a test case that's broken by this bug.
Coercions to some extent are intentional. You're allowed to encode an Int64
and decode it as Int8
which will truncate it.
I don't think so. Float to Double is perfectly fine, but not vice versa.
First of all, you should not actually use Float in haskell code :) https://wiki.haskell.org/Performance/Floating_point