This is an archive of the discontinued LLVM Phabricator instance.

[libc] Correct rounding for hexadecimalStringToFloat with long inputs.
ClosedPublic

Authored by lntue on Nov 12 2021, 4:06 PM.

Details

Summary

Update binaryExpTofloat so that it will round correctly for long inputs when converting hexadecimal strings to floating points.

Diff Detail

Event Timeline

lntue created this revision.Nov 12 2021, 4:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 12 2021, 4:06 PM
lntue requested review of this revision.Nov 12 2021, 4:06 PM
michaelrj added inline comments.Nov 15 2021, 10:04 AM
libc/src/__support/str_to_float.h
522

This is unnecessary, since the FloatBits type will do it when setting the mantissa of the final value. It also doesn't really hurt anything to have it, but I generally prefer to get the full output bits for testing.

662–665

setting seenDigit to false isn't recommended, since it should just be a flag for if any digit has been seen. This particular if would cause numbers that end with alphanumeric characters that aren't in base to return as zero, for example 0x1z.

lntue updated this revision to Diff 387333.Nov 15 2021, 11:22 AM
lntue marked an inline comment as done.

[libc] Correct rounding for hexadecimalStringToFloat with long inputs.

libc/src/__support/str_to_float.h
522

I think it is better for maintainability and consistency to have the outputs well-defined (as is expected results bits in the answer) instead of relying on the caller to do the cleanup without being documented. For instance, without this clean up, INF results might have outputMantissa == 0, 2^mantissaLength, or 2^(mantissaLength+1).

michaelrj accepted this revision.Nov 16 2021, 10:44 AM

LGTM

libc/src/__support/str_to_float.h
522

That seems reasonable, in that case I should probably go fix the other functions to match, although that will require fixing a lot of tests.

This revision is now accepted and ready to land.Nov 16 2021, 10:44 AM
lntue updated this revision to Diff 387720.Nov 16 2021, 11:30 AM

[libc] Correct rounding for hexadecimalStringToFloat with long inputs.

This revision was landed with ongoing or failed builds.Nov 16 2021, 11:31 AM
This revision was automatically updated to reflect the committed changes.