support for encoding/decoding IEEE single/double precision binary floating point
ananthakumaran opened this issue · comments
This is more of a feature request. Currently, elixir does support decoding single and double precision float via binary pattern match(<<n::64-float-big>>), but unfortunately, the underlying Erlang implementation is buggy. Especially it doesn't support special values like NaN, Infinity etc. This makes it difficult to write a fully conforming implementation.
I think it is better to wrap decimal to handle the nan/infinity cases rather than adding support to Decimal. I am hesitant to adding more float support since the conversion is not exact.
Here is an example that should get you close: https://github.com/elixir-ecto/postgrex/blob/master/lib/postgrex/extensions/float8.ex#L23-L26.
Thanks for the reference implementation.
The main reason I opened the issue here is, I am myself not familiar with the spec and from a cursory look, it seems to have a lot of special cases. I thought having it in a standard place would prevent everybody from implementing the same thing in a slightly different/buggy way.
The special cases you should be concerned about in this cases are all handled in the example code that I linked.