fix double rounding of subnormal hex-floats in StringToDouble - #316
Open
Ramya-9353 wants to merge 1 commit into
Open
Ramya-9353 wants to merge 1 commit into
Ramya-9353 wants to merge 1 commit into
Conversation
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.
Repro: with ALLOW_HEX_FLOATS, StringToDouble("0xcc5f893a94ec6.a8ap-1074") returns 1.7763493645383205e-308, one ulp below the value strtod and the exact value round to (1.776349364538321e-308). Hex-floats whose significand needs more than 53 bits and whose magnitude is subnormal can be a ulp out.
Cause: RadixStringToIeee rounds the significand to 53 bits (round-to-nearest) and then forms the result with ldexp. For a subnormal result ldexp rounds a second time onto the narrower 2^-1074 subnormal grid, so the value is rounded twice. #304 fixed the same double rounding on the StringToFloat path, but the StringToDouble path still rounds to nearest at 53 bits before the subnormal ldexp.
Fix: keep the exact significand, its dropped-bit count and a sticky bit; when the result is subnormal, round the exact significand once, straight onto the 2^-1074 grid, so ldexp only has to place it. Normal results, and the float, decimal, hex-integer and octal paths, are unchanged. Checked against strtod over a wide sweep of subnormal hex-floats.