Repository navigation
fix: keep every digit of a float slice - #546
Open
shounakjoshi88-a11y wants to merge 1 commit into
Open
shounakjoshi88-a11y wants to merge 1 commit into
shounakjoshi88-a11y wants to merge 1 commit into
Conversation
The float slice values rendered themselves with %f, which is six decimals, and the accessors re-parsed that rendering, so GetFloat64Slice returned values that had lost their precision: 1e-7 came back as 0 and 123456789.123456789 came back as 123456789.123457. Every other numeric kind renders itself with strconv.Format* and the precision -1, so the float slices do the same.
|
|
Author
|
The
The new test fails on the unmodified tree: and passes with the change. |
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.
The float slice values rendered themselves with
%f, which is six decimals:and the accessors re-parse that rendering (
getFlagTypereadsValue.String()and runs it through the converter), soGetFloat64Slicereturned values that had lost their precision:binds
[1e-07 0.1 1.2345678912345679e+08 5e-324], butGetFloat64Slicereturned[0 0.1 1.23456789123457e+08 0].Every other numeric kind renders itself with
strconv.Format*and the precision -1 (float64Valueusesstrconv.FormatFloat(float64(*f), 'g', -1, 64)), so the float slices do the same now.GetFloat32Slicehad the same fault and is fixed with it.The new test in
float64_slice_test.goparses a flag with more digits than%fkeeps and compares the accessor with the bound variable. It fails without the change:and passes with it.