Skip to content

fix double rounding of subnormal hex-floats in StringToDouble - #316

Open
Ramya-9353 wants to merge 1 commit into
google:masterfrom
Ramya-9353:hex-float-subnormal-double-rounding
Open

Ramya-9353 wants to merge 1 commit into
google:masterfrom
Ramya-9353:hex-float-subnormal-double-rounding

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant