aboutsummaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2013-04-17 21:19:19 +1000
committerAndrew Tridgell <tridge@samba.org>2013-05-04 19:17:15 +1000
commitb06098a5406cf3269a313362b43d7f47b160933b (patch)
tree2f3955657fb0e69a56642fa192d470589b1b431b /nuttx
parenta627f6c0eba3cfb0471b0ff88652d85c6d7cb0ca (diff)
downloadpx4-firmware-b06098a5406cf3269a313362b43d7f47b160933b.tar.gz
px4-firmware-b06098a5406cf3269a313362b43d7f47b160933b.tar.bz2
px4-firmware-b06098a5406cf3269a313362b43d7f47b160933b.zip
libdtoa: fixed handling of NaN and Infinity
otherwise we print thousands of 00000 characters
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/libc/stdio/lib_libdtoa.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/nuttx/libc/stdio/lib_libdtoa.c b/nuttx/libc/stdio/lib_libdtoa.c
index 29f61fd76..84e3ee50b 100644
--- a/nuttx/libc/stdio/lib_libdtoa.c
+++ b/nuttx/libc/stdio/lib_libdtoa.c
@@ -43,6 +43,7 @@
/****************************************************************************
* Included Files
****************************************************************************/
+#include <math.h>
/****************************************************************************
* Pre-processor Definitions
@@ -104,6 +105,13 @@ static void zeroes(FAR struct lib_outstream_s *obj, int nzeroes)
* Private Functions
****************************************************************************/
+static void lib_dtoa_string(FAR struct lib_outstream_s *obj, const char *str)
+{
+ while (*str) {
+ obj->put(obj, *str++);
+ }
+}
+
/****************************************************************************
* Name: lib_dtoa
*
@@ -138,8 +146,21 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec,
int dsgn; /* Unused sign indicator */
int i;
- /* Non-zero... positive or negative */
+ /* special handling for NaN and Infinity */
+ if (isnan(value)) {
+ lib_dtoa_string(obj, "NaN");
+ return;
+ }
+ if (isinf(value)) {
+ if (value < 0.0d) {
+ obj->put(obj, '-');
+ }
+ lib_dtoa_string(obj, "Infinity");
+ return;
+ }
+ /* Non-zero... positive or negative */
+
if (value < 0)
{
value = -value;