Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IEEE 754 NaN / infinity #53

Merged
merged 11 commits into from
Dec 28, 2020

Conversation

CandyGumdrop
Copy link
Contributor

@CandyGumdrop CandyGumdrop commented Aug 15, 2019

This enables unpacking of 32-bit and 64-bit floating-point NaN, +infinity and -infinity, to the values :NaN, :inf and :"-inf", but does not support packing those atoms back into Messagepack floats (as these atoms would otherwise be packed into strings and this could be considered a breaking change).

I chose these atom values as there is a precedent in the mongodb library, but these could perhaps be changed to other values, such as :nan rather than :NaN.

None of this is really ideal since Erlang doesn't support NaN or infinity in floats, but this at least provides some handling of these values which are supported by Messagepack.

@CandyGumdrop CandyGumdrop force-pushed the unpack-ieee754 branch 2 times, most recently from af74d5f to 96a994f Compare August 15, 2019 16:43
This enables unpacking of 32-bit and 64-bit floating-point NaN,
+infinity and -infinity, to the values `:NaN`, `:inf` and `:"-inf"`, but
does not support packing those atoms back into Messagepack floats.
@lukaszsamson
Copy link

I just got bitten by this. Can we get this merged?
If there is no plan to support NaN and Inf at least msgpax could raise a more meaningful error message than

** (Msgpax.UnpackError) invalid format, first byte: 203
    (msgpax 2.2.4) lib/msgpax.ex:252: Msgpax.unpack!/2

First byte 203 is definitely a valid format ;)

test/msgpax_test.exs Outdated Show resolved Hide resolved
test/msgpax_test.exs Outdated Show resolved Hide resolved
lib/msgpax/packer.ex Outdated Show resolved Hide resolved
lexmag and others added 5 commits December 28, 2020 21:23
Co-authored-by: Cẩm Huỳnh <huynhquancam@gmail.com>
Co-authored-by: Cẩm Huỳnh <huynhquancam@gmail.com>
@lexmag lexmag merged commit 3b93d43 into lexmag:master Dec 28, 2020
@lexmag
Copy link
Owner

lexmag commented Dec 28, 2020

@CandyGumdrop thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants