You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
If you consider adding more granularity for numbers, then I can add a parsing method in jsoniter-scala-core that will parse JSON numbers to the most suitable implementation of java.lang.Number that can hold it without rounding (or some subset of implementations, like: Int, Long, scala.math.BigInteger, Float, Double, scala.math.BigDecimal).
Looks like we've agreed that this should be done as part of the 0.19 release, so such a function in jsoniter would be great to have sometime in the next 2 months (I expect to have more time to work/organize on smithy4s starting from the next year)
For some values following doesn't hold
The reasons is that
Document
has only one type for all numeric values -DNumber
that is backed byBigDecimal
.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 as123.4
json number literal. On the right hand side we will instead get123.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 theDocument
type.The text was updated successfully, but these errors were encountered: