diff --git a/TODO b/TODO index 82ab76d39b3..92b2b541e08 100644 --- a/TODO +++ b/TODO @@ -22,7 +22,7 @@ nuttx/: (18) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) (2) Other drivers (drivers/) - (10) Libraries (libs/libc/, libs/libm/) + (9) Libraries (libs/libc/, libs/libm/) (12) File system/Generic drivers (fs/, drivers/) (10) Graphics Subsystem (graphics/) (1) Build system / Toolchains @@ -1977,14 +1977,6 @@ o Libraries (libs/libc/, libs/libm/) Status: Open Priority: Medium (this might important to someone). - Title: FLOATING POINT PRECISION - Description: A fieldwidth and precision is required with the %f format. If %f - is used with no format, than floating numbers will be printed with - a precision of 0 (effectively presented as integers). - Update: Correct, but only with CONFIG_NANO_PRINTF=y. - Status: Open - Priority: Medium (this might important to someone). - Title: LIBM INACCURACIES Description: "..if you are writing something like robot control or inertial navigation system for aircraft, I have found diff --git a/libs/libc/stdio/lib_libvsprintf.c b/libs/libc/stdio/lib_libvsprintf.c index d84b785486f..2d8758a26e1 100644 --- a/libs/libc/stdio/lib_libvsprintf.c +++ b/libs/libc/stdio/lib_libvsprintf.c @@ -118,6 +118,10 @@ # define FMT_PREV src-- /* Backup to the previous character */ #endif +/* Default precision to use with %f format if no precision is specified. */ + +#define FLOAT_PRECISION_DEFAULT 6 + /**************************************************************************** * Private Type Declarations ****************************************************************************/ @@ -1555,6 +1559,13 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const IPTR char *src, double dblval = va_arg(ap, double); int dblsize; + /* Set to default precision if none specified */ + + if (!IS_HASDOT(flags) && trunc == 0) + { + trunc = FLOAT_PRECISION_DEFAULT; + } + /* Get the width of the output */ dblsize = getdblsize(FMT_CHAR, trunc, flags, dblval);