is_nan and is_infinity macros

This commit is contained in:
Max Bruckner
2018-01-20 15:14:27 +01:00
parent 5af3271726
commit deca87b071
2 changed files with 24 additions and 2 deletions

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");
}