This patch adds the final conversion to printf, %g. This is a floating
point conversion that selects automatically between the %e and %f
formats based on the precision requested and resulting exponent.
Additionally it trims trailing zeroes. With this done all that's left
for finishing printf is adding long double support to the decimal float
conversions.
Details
- Reviewers
sivachandra lntue - Commits
- rG173d50235fa3: [libc] add printf auto float conversion
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/src/stdio/printf_core/float_dec_converter.h | ||
---|---|---|
807 | above this line are minor bugfixes I made to the previous conversion (%e) that I discovered while testing the new conversion. All the new code is below this line. |
adjust comments
libc/test/src/stdio/sprintf_test.cpp | ||
---|---|---|
2121 | Probably yes, but it's also here to explain why the long double tests are commented out. | |
2699 | I commented it out because I was testing the code with the system's sprintf, and this test was causing a segfault. I'll likely remove this test and the special case I put in in a separate patch because it's not necessary or in the standard. |
libc/test/src/stdio/sprintf_test.cpp | ||
---|---|---|
2121 | In the test, you should add a comment like, TODO: Uncomment the below tests after long double support is added. And in the implementaiton, add a comment like, `TODO: Extend the algorithm for long doubles with a bigger table, or use an alternate algorithm." Otherwise, it feels like the TODO is for the tests and not for the implementation. |
above this line are minor bugfixes I made to the previous conversion (%e) that I discovered while testing the new conversion. All the new code is below this line.