Render the number nicely from the given item into a string. */
| 125 | |
| 126 | /* Render the number nicely from the given item into a string. */ |
| 127 | static char *print_number(Json* item) |
| 128 | { |
| 129 | char *str; |
| 130 | double d=item->mValueDouble; |
| 131 | if (fabs(((double)item->mValueInt)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN) |
| 132 | { |
| 133 | str=(char*)Json::malloc(21); /* 2^64+1 can be represented in 21 chars. */ |
| 134 | if (str) sprintf(str,"%d",item->mValueInt); |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | str=(char*)Json::malloc(64); /* This is a nice tradeoff. */ |
| 139 | if (str) |
| 140 | { |
| 141 | if (fabs(floor(d)-d)<=DBL_EPSILON && fabs(d)<1.0e60)sprintf(str,"%.0f",d); |
| 142 | else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); |
| 143 | else sprintf(str,"%f",d); |
| 144 | } |
| 145 | } |
| 146 | return str; |
| 147 | } |
| 148 | |
| 149 | static unsigned parse_hex4(const char *str) |
| 150 | { |