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

Allow more precise representation of numeric types in Document #1579

Open
ghostbuster91 opened this issue Sep 5, 2024 · 0 comments
Open
Milestone

Comments

@ghostbuster91
Copy link
Contributor

For some values following doesn't hold

Json.payloadCodecs.encoders.fromSchema[MyStructure].apply(MyStructure(...)) 
=== 
Json.payloadCodecs.encoders.fromSchema[Document].apply(Document.encode(MyStructure(...))) 

The reasons is that Document has only one type for all numeric values - DNumber that is backed by BigDecimal.
Some json encoders including the one from jsonitter perform a clever optimization in order to render float values in an optimal way. That can't done on the right side because we lost the information that it was a single precision floating point number.
The left side will encode 123.4 float value as 123.4 json number literal. On the right hand side we will instead get 123.4000015258789 which is the closest number that can be represented in binary format when using IEEE 754 encoding.

While this is not an issue for IEE 754 compatible parsers (so almost everyone), extending the Document ADT with more granular types for numeric values will allow greater control over how are they encoded when going through the Document type.

@kubukoz kubukoz added this to the 0.19.0 milestone Sep 5, 2024
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

No branches or pull requests

2 participants