This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5e49036641bcc96366808cb8d42fd79b87950b64 Author: chao an <[email protected]> AuthorDate: Mon Nov 2 11:31:16 2026 +0800 libc/stdio: Batch NaN and Inf writes NaN and Inf formatting only emits fixed three-byte strings. Select the pre-cased spelling up front and write it in one stream operation instead of converting and outputting each character separately. Signed-off-by: chao an <[email protected]> --- libs/libc/stream/lib_libvsprintf.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/libs/libc/stream/lib_libvsprintf.c b/libs/libc/stream/lib_libvsprintf.c index 282160ba705..83acd7da80e 100644 --- a/libs/libc/stream/lib_libvsprintf.c +++ b/libs/libc/stream/lib_libvsprintf.c @@ -137,6 +137,12 @@ struct arg_s ****************************************************************************/ static const char g_nullstring[] = "(null)"; +#ifdef CONFIG_LIBC_FLOATINGPOINT +static const char g_inf_lower[] = "inf"; +static const char g_nan_lower[] = "nan"; +static const char g_inf_upper[] = "INF"; +static const char g_nan_upper[] = "NAN"; +#endif static const char g_spaces[REPEAT_BUFLEN] = " "; static const char g_zeroes[REPEAT_BUFLEN] = "0000000000000000"; @@ -742,26 +748,17 @@ flt_oper: stream_putc(sign, stream); } - p = "inf"; if (_dtoa.flags & DTOA_NAN) { - p = "nan"; + p = (flags & FL_FLTUPP) != 0 ? g_nan_upper : g_nan_lower; } - -# if ('I'-'i' != 'N'-'n') || ('I'-'i' != 'F'-'f') || ('I'-'i' != 'A'-'a') -# error -# endif - while ((ndigs = *p) != 0) + else { - if ((flags & FL_FLTUPP) != 0) - { - ndigs += 'I' - 'i'; - } - - stream_putc(ndigs, stream); - p++; + p = (flags & FL_FLTUPP) != 0 ? g_inf_upper : g_inf_lower; } + stream_puts(p, 3, stream); + goto tail; }
