MCPcopy Create free account
hub / github.com/beefytech/Beef / print_number

Function print_number

BeefySysLib/util/Json.cpp:127–147  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

125
126/* Render the number nicely from the given item into a string. */
127static 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
149static unsigned parse_hex4(const char *str)
150{

Callers 1

print_valueFunction · 0.85

Calls 1

mallocFunction · 0.50

Tested by

no test coverage detected