MCPcopy Create free account
hub / github.com/Tencent/TAD_Sim / print_double

Function print_double

common/map_sdk/transmission/src/cJSON.cpp:138–152  ·  view source on GitHub ↗

Render the number nicely from the given item into a string. */

Source from the content-addressed store, hash-verified

136
137/* Render the number nicely from the given item into a string. */
138static char *print_double(cJSON *item) {
139 char *str;
140 double d = item->valuedouble;
141 str = reinterpret_cast<char *>(cJSON_malloc(64)); /* This is a nice tradeoff. */
142 if (str) {
143 if (fabs(floor(d) - d) <= DBL_EPSILON) {
144 sprintf(str, "%.0f", d);
145 } else if (fabs(d) < 1.0e-6 || fabs(d) > 1.0e9) {
146 sprintf(str, "%lf", d);
147 } else {
148 sprintf(str, "%f", d);
149 }
150 }
151 return str;
152}
153
154static char *print_int(cJSON *item) {
155 char *str;

Callers 1

print_valueFunction · 0.85

Calls 1

fabsFunction · 0.85

Tested by

no test coverage detected