Fix encodings for zero valued big.Floats with non-zero precisions. - #118
Merged
Conversation
bigFloatCodec classified a value as zero using `prec == 0`, but a big.Float's precision is independent of its value. Only new(big.Float) and var-declared zeros have precision 0; zeros from big.NewFloat(0) or from arithmetic carry a nonzero precision (53 for NewFloat). Those zeros fell through to the finite-number path and were encoded with exponent 0, sorting them as though they were large finite values. Concretely, big.NewFloat(0) encoded greater than 0.25 and 1e-300, and -1e-300 encoded greater than -0.0, breaking the codec's ordering guarantee. Detect zero with value.Sign() == 0 instead. The existing tests missed this because every zero they construct uses var/new(big.Float), which has precision 0. Add TestBigFloatZeroPrecision covering precision-bearing signed zeros against small finite neighbors. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
It is a partial fix, but zeroes with different precisions need to be encoded differently. The existing tests should be modified to include new test cases instead of adding a new test here.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix encodings for zero-valued big.Floats with non-zero precisions.
Previously zero values were encoded without precision or mode.
Claude did identify that there was a problem in how the code detected
a value was zero (using big.Float.Prec() instead of big.Float.Sign()),
but got the nature of the fix wrong. It only corrected the detection,
but did not change the encoding, so the encoding is not reversible.
Claude's fix is in the first commit.