This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add a convenience class and function for integer to string conversion.
ClosedPublic

Authored by sivachandra on Jul 21 2022, 1:27 AM.

Details

Summary

Printf's integer converter has been modified to use the new converter. In
future, it will be used to implement other parts of the libc.

Diff Detail

Event Timeline

sivachandra created this revision.Jul 21 2022, 1:27 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 21 2022, 1:27 AM
sivachandra requested review of this revision.Jul 21 2022, 1:27 AM

Fix copy-pasted comments.

overall LGTM, with a few comments

libc/src/__support/integer_to_string.h
34–35

for integer division you can just add (divisor - 1) to the initial number to get ceil, so in this case it would be ((sizeof(T) * 5) + 1) / 2)

libc/test/src/__support/integer_to_string_test.cpp
21

would it be better to implement an equality checker for string views?

sivachandra marked an inline comment as done.

Address comments.

libc/test/src/__support/integer_to_string_test.cpp
21

Yes, I think we should. I will do it in a separate patch.

This revision is now accepted and ready to land.Jul 21 2022, 1:00 PM
This revision was landed with ongoing or failed builds.Jul 21 2022, 1:19 PM
This revision was automatically updated to reflect the committed changes.