This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix mixed-sign comparison warnings and an out-of-bound access in high_precision_decimal.h
ClosedPublic

Authored by lntue on Feb 7 2022, 9:40 AM.

Details

Summary

Fix mixed-sign comparison warnings and an out-of-bound access in high_precision_decimal.h

Diff Detail

Event Timeline

lntue created this revision.Feb 7 2022, 9:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2022, 9:40 AM
lntue requested review of this revision.Feb 7 2022, 9:40 AM
michaelrj added inline comments.Feb 7 2022, 10:14 AM
libc/src/__support/high_precision_decimal.h
131

I think that instead of having this, you could change the condition at the start of the function from roundToDigit < 0 to roundToDigit <= 0, and it would have a more useful effect. If we're requesting 0 digits, then it should always round down, even if it's truncated.

lntue added inline comments.Feb 7 2022, 10:17 AM
libc/src/__support/high_precision_decimal.h
131

Then it will return false for something that needs roundup like ".51".

michaelrj accepted this revision.Feb 7 2022, 10:42 AM

LGTM

libc/src/__support/high_precision_decimal.h
131

ah, yes, I see what you mean, nevermind then.

This revision is now accepted and ready to land.Feb 7 2022, 10:42 AM

as an additional part of this patch, could you add
`simple_decimal_conversion_test<float>(

"7.00649232162408535461864791644958065640130970938257885878534141944895541342930300743319094181060791015625e-46", 0x0, 0,
ERANGE);`

to line 235 of str_to_float_test.cpp?

lntue updated this revision to Diff 406577.Feb 7 2022, 12:38 PM

Add test to str_to_float_test.cpp.