Support for printing NaN and infinity from Andrew Tridgell

This commit is contained in:
Gregory Nutt
2013-04-17 07:40:48 -06:00
parent 504b25ee2b
commit 06871729dd
+38 -1
View File
@@ -44,6 +44,8 @@
* Included Files
****************************************************************************/
#include <math.h>
#include "lib_internal.h"
/****************************************************************************
@@ -84,6 +86,10 @@
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: zeroes
*
@@ -103,9 +109,21 @@ static void zeroes(FAR struct lib_outstream_s *obj, int nzeroes)
}
/****************************************************************************
* Private Functions
* Name: lib_dtoa_string
*
* Description:
* Print the specified string
*
****************************************************************************/
static void lib_dtoa_string(FAR struct lib_outstream_s *obj, const char *str)
{
while (*str)
{
obj->put(obj, *str++);
}
}
/****************************************************************************
* Name: lib_dtoa
*
@@ -140,6 +158,25 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec,
int dsgn; /* Unused sign indicator */
int i;
/* 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)