is_nan and is_infinity macros

This commit is contained in:
Max Bruckner
2018-03-25 13:01:06 +02:00
parent 3e2c29528a
commit 5ed383a0d1
2 changed files with 24 additions and 2 deletions
+4 -2
View File
@@ -471,6 +471,9 @@ static void update_offset(printbuffer * const buffer)
buffer->offset += strlen((const char*)buffer_pointer);
}
#define is_nan(number) (number != number)
#define is_infinity(number) (!is_nan(number) && (number * 0) != 0)
/* Render the number nicely from the given item into a string. */
static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer)
{
@@ -487,8 +490,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
return false;
}
/* This checks for NaN and Infinity */
if ((d * 0) != 0)
if (is_nan(d) || is_infinity(d))
{
length = sprintf((char*)number_buffer, "null");
}