From df1fb62439b601b4f6c30a152ff25b0a7928bfdf Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Thu, 5 Aug 2021 23:43:56 +0300 Subject: [PATCH] Fixes mpaland/printf#121 : Special-casing 0 and -0 in the "%g"-related exponent check, since their exponent is a special case - 0 rather minus infinity. --- printf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printf.c b/printf.c index 2e2ec1eb..e90ca2b3 100644 --- a/printf.c +++ b/printf.c @@ -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); }