xiaoxiang781216 commented on code in PR #21537:
URL: https://github.com/apache/nuttx/pull/21537#discussion_r4506230424
##########
libs/libc/stream/lib_libbsprintf.c:
##########
@@ -142,6 +151,41 @@ int lib_bsprintf(FAR struct lib_outstream_s *s, FAR const
IPTR char *fmt,
infmt = false;
}
+#ifdef CONFIG_LIBC_BFORMAT_B16
+ else if (strchr("aAeEfFgG", c) != NULL && *(fmt - 2) == 'h')
Review Comment:
standard already define h prefix, why do you reuse it for b16_t?
##########
libs/libc/stream/lib_libbsprintf.c:
##########
@@ -142,6 +151,41 @@ int lib_bsprintf(FAR struct lib_outstream_s *s, FAR const
IPTR char *fmt,
infmt = false;
}
+#ifdef CONFIG_LIBC_BFORMAT_B16
+ else if (strchr("aAeEfFgG", c) != NULL && *(fmt - 2) == 'h')
+ {
+ /* %hf is a b16_t (16.16 fixed-point) value */
+
+ offset += sizeof(var->b16);
+
+# ifdef CONFIG_LIBC_FLOATINGPOINT
+ ret += lib_sprintf(s, fmtstr, b16tod(var->b16));
+# else
+ /* No floating point printf: print as integer.fraction with four
+ * decimal digits. The width and precision are ignored.
+ */
+
+ {
+ uint32_t uv = var->b16 < 0 ? -(uint32_t)var->b16 :
+ (uint32_t)var->b16;
+ uint32_t ip = uv >> 16;
+ uint32_t fp = (uint32_t)((((uint64_t)(uv & 0xffff)) * 10000 +
+ 0x8000) >> 16);
+
+ if (fp >= 10000)
+ {
+ ip++;
+ fp -= 10000;
+ }
+
+ ret += lib_sprintf(s, "%s%" PRIu32 ".%04" PRIu32,
Review Comment:
why not modify lib_vsrpintf_internal
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]