[libc-commits] [libc] [libc][printf] Fix %e/%g formatting in float320 algorithm (PR #232721)
Simon Tatham via libc-commits
libc-commits at lists.llvm.org
Fri Oct 16 05:36:41 PDT 2026
https://github.com/statham-arm created https://github.com/llvm/llvm-project/pull/232721
Commit 509679cf9c9db71, updating arrays of char to a more general CharT, removed a memset in the float320 code and replaced it with default zero-initialization of the containing object. But the memset was to `'0'`, not to `0`, so this changed the output. Restored the correct initialization, this time using a for loop so that it will work even if CharT is >1 byte.
>From 290fca34aefd275407127e749b8bc9cf1abb279f Mon Sep 17 00:00:00 2001
From: Simon Tatham <simon.tatham at arm.com>
Date: Fri, 16 Oct 2026 13:21:24 +0100
Subject: [PATCH] [libc][printf] Fix %e/%g formatting in float320 algorithm
Commit 509679cf9c9db71, updating arrays of char to a more general
CharT, removed a memset in the float320 code and replaced it with
default zero-initialization of the containing object. But the memset
was to `'0'`, not to `0`, so this changed the output. Restored the
correct initialization, this time using a for loop so that it will
work even if CharT is >1 byte.
---
libc/src/__support/printf_core/float_dec_converter_limited.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/printf_core/float_dec_converter_limited.h b/libc/src/__support/printf_core/float_dec_converter_limited.h
index 39e332ff91714..0a21784c61b1a 100644
--- a/libc/src/__support/printf_core/float_dec_converter_limited.h
+++ b/libc/src/__support/printf_core/float_dec_converter_limited.h
@@ -145,8 +145,9 @@ LIBC_INLINE DigitsOutput<CharT> decimal_digits(DigitsInput input, int precision,
output.ndigits = 0;
output.exponent = -precision - 1;
} else {
- // In E mode, set the expected number of 0s (output.digits has been
- // value-initialized to all zeroes).
+ // In E mode, generate a string containing the expected number of 0s.
+ for (int i = 0; i < precision; ++i)
+ output.digits[i] = CharT{'0'};
output.ndigits = precision;
output.exponent = 0;
}
More information about the libc-commits
mailing list