Skip to content

Commit

Permalink
Fixes mpaland#121 : Special-casing 0 and -0 in the "%g"-related expon…
Browse files Browse the repository at this point in the history
…ent check, since their exponent is a special case - 0 rather minus infinity.
  • Loading branch information
eyalroz committed Aug 6, 2021
1 parent 7d2a357 commit 4d6800e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ static size_t sprint_exponential_number(out_fct_type out, char* buffer, size_t i
// in "%g" mode, "precision" is the number of _significant digits_ not decimals
if (flags & FLAGS_ADAPT_EXP) {
// do we want to fall-back to "%f" mode?
if ((abs_number >= 1e-4) && (abs_number < 1e6)) {
if ((abs_number == 0.) || ((abs_number >= 1e-4) && (abs_number < 1e6))) {
if ((int)precision > exp10) {
precision = (unsigned)((int)precision - exp10 - 1);
}
Expand Down

0 comments on commit 4d6800e

Please sign in to comment.