diff --git a/printf.c b/printf.c index 52483991..11e90a85 100644 --- a/printf.c +++ b/printf.c @@ -575,7 +575,17 @@ static size_t sprint_exponential_number(out_fct_type out, char* buffer, size_t i // output the floating part const size_t start_idx = idx; - idx = sprint_decimal_number(out, buffer, idx, maxlen, negative ? -abs_number : abs_number, precision, fwidth, flags, buf, len); + struct double_components number_ = get_components(negative ? -abs_number : abs_number, precision); + // For "%e" notation, the integral part must be between 1 and 9; but the rounding can potentially + // bring it up from, say, 9.999something to 10 - in which case we must "steal" this extra 10 in + // favor of the exponent + if (!(flags & FLAGS_ADAPT_EXP) && number_.integral >= 10) { + number_.integral = 1; + number_.fractional = 0; + exp10++; + } + // TODO: Do we need to check for number_.integral being 0? + idx = sprint_broken_up_decimal(number_, out, buffer, idx, maxlen, precision, fwidth, flags, buf, len); // output the exp10 part if (minwidth) {