Skip to content

Commit

Permalink
[libc] add exponent format to printf
Browse files Browse the repository at this point in the history
Add support for the %e/E conversion in printf, as well as unit tests. It
does not yet support long doubles.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D140042
  • Loading branch information
michaelrj-google committed Dec 22, 2022
1 parent f85cc60 commit 5112651
Show file tree
Hide file tree
Showing 4 changed files with 986 additions and 32 deletions.
9 changes: 9 additions & 0 deletions libc/src/__support/float_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ class FloatToString {
return 0;
}
}

constexpr BlockInt get_block(int block_index) {
if (block_index >= 0) {
return get_positive_block(block_index);
} else {
return get_negative_block(-1 - block_index);
}
}

constexpr size_t get_positive_blocks() {
if (exponent >= -MANT_WIDTH) {
const uint32_t idx =
Expand Down
6 changes: 3 additions & 3 deletions libc/src/stdio/printf_core/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ int convert(Writer *writer, const FormatSection &to_conv) {
case 'f':
case 'F':
return convert_float_decimal(writer, to_conv);
// case 'e':
// case 'E':
// return convert_float_dec_exp(writer, to_conv);
case 'e':
case 'E':
return convert_float_dec_exp(writer, to_conv);
case 'a':
case 'A':
return convert_float_hex_exp(writer, to_conv);
Expand Down
Loading

0 comments on commit 5112651

Please sign in to comment.