-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msgpack: Never marshal integers as MessagePack float
Previously we were using MessagePack's float family for anything that could convert losslessly to float64. Unfortunately, cty's interpretation of numbers uses binary floating point internally but decimal strings as the presentation, including when numbers are converted to strings, and so we need to make some assumptions about precision when we're choosing a string representation of a number, to avoid confusing situations where slight inaccuracy in the binary interpretation of a number presented in decimal would appear as unwanted extra digits in the string representation. Slight differences caused by precision handling are acceptable for the fractional parts of numbers, but callers expect integers to be presented exactly as originally given. Round-tripping a large integer through a float64, even if the binary representation is exact, causes us to end up with a rounded string representation after decoding, because the decoded number has 52-bit precision instead of the 512 we use when dealing with string representations of large integers. Therefore we'll now use MessagePack float encodings only for numbers that have a fractional component. If an integer cannot fit in any of MessagePack's integer encodings then we'll encode it as a string containing decimal digits instead, so that it'll decode back to a number with the same precision and thus the same decimal string representation.
- Loading branch information
1 parent
0e3c880
commit f41ae52
Showing
3 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters