提交 dd4cb540 编写于 作者: M Max Bruckner

print_number: Remove unnecessary integer handling

上级 1ea72f82
...@@ -368,21 +368,6 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const ...@@ -368,21 +368,6 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const
return NULL; return NULL;
} }
/* value is an int */
if ((fabs(((double)item->valueint) - d) <= DBL_EPSILON) && (d <= INT_MAX) && (d >= INT_MIN))
{
trim_zeroes = false; /* don't remove zeroes for integers */
/* 2^64+1 can be represented in 21 chars. */
output_pointer = ensure(output_buffer, 21, hooks);
if (output_pointer != NULL)
{
length = sprintf((char*)output_pointer, "%d", item->valueint);
}
}
/* value is a floating point number */
else
{
/* This is a nice tradeoff. */ /* This is a nice tradeoff. */
output_pointer = ensure(output_buffer, 64, hooks); output_pointer = ensure(output_buffer, 64, hooks);
if (output_pointer != NULL) if (output_pointer != NULL)
...@@ -394,6 +379,7 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const ...@@ -394,6 +379,7 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const
} }
else if ((fabs(floor(d) - d) <= DBL_EPSILON) && (fabs(d) < 1.0e60)) else if ((fabs(floor(d) - d) <= DBL_EPSILON) && (fabs(d) < 1.0e60))
{ {
/* integer */
length = sprintf((char*)output_pointer, "%.0f", d); length = sprintf((char*)output_pointer, "%.0f", d);
trim_zeroes = false; /* don't remove zeroes for "big integers" */ trim_zeroes = false; /* don't remove zeroes for "big integers" */
} }
...@@ -407,7 +393,6 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const ...@@ -407,7 +393,6 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const
length = sprintf((char*)output_pointer, "%f", d); length = sprintf((char*)output_pointer, "%f", d);
} }
} }
}
/* sprintf failed */ /* sprintf failed */
if (length < 0) if (length < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册