MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlXPathFormatNumber

Function xmlXPathFormatNumber

ThirdParty/libxml2/vtklibxml2/xpath.c:2320–2436  ·  view source on GitHub ↗

* xmlXPathFormatNumber: * @number: number to format * @buffer: output buffer * @buffersize: size of output buffer * * Convert the number into a string representation. */

Source from the content-addressed store, hash-verified

2318 * Convert the number into a string representation.
2319 */
2320static void
2321xmlXPathFormatNumber(double number, char buffer[], int buffersize)
2322{
2323 switch (xmlXPathIsInf(number)) {
2324 case 1:
2325 if (buffersize > (int)sizeof("Infinity"))
2326 snprintf(buffer, buffersize, "Infinity");
2327 break;
2328 case -1:
2329 if (buffersize > (int)sizeof("-Infinity"))
2330 snprintf(buffer, buffersize, "-Infinity");
2331 break;
2332 default:
2333 if (xmlXPathIsNaN(number)) {
2334 if (buffersize > (int)sizeof("NaN"))
2335 snprintf(buffer, buffersize, "NaN");
2336 } else if (number == 0) {
2337 /* Omit sign for negative zero. */
2338 snprintf(buffer, buffersize, "0");
2339 } else if ((number > INT_MIN) && (number < INT_MAX) &&
2340 (number == (int) number)) {
2341 char work[30];
2342 char *ptr, *cur;
2343 int value = (int) number;
2344
2345 ptr = &buffer[0];
2346 if (value == 0) {
2347 *ptr++ = '0';
2348 } else {
2349 snprintf(work, 29, "%d", value);
2350 cur = &work[0];
2351 while ((*cur) && (ptr - buffer < buffersize)) {
2352 *ptr++ = *cur++;
2353 }
2354 }
2355 if (ptr - buffer < buffersize) {
2356 *ptr = 0;
2357 } else if (buffersize > 0) {
2358 ptr--;
2359 *ptr = 0;
2360 }
2361 } else {
2362 /*
2363 For the dimension of work,
2364 DBL_DIG is number of significant digits
2365 EXPONENT is only needed for "scientific notation"
2366 3 is sign, decimal point, and terminating zero
2367 LOWER_DOUBLE_EXP is max number of leading zeroes in fraction
2368 Note that this dimension is slightly (a few characters)
2369 larger than actually necessary.
2370 */
2371 char work[DBL_DIG + EXPONENT_DIGITS + 3 + LOWER_DOUBLE_EXP];
2372 int integer_place, fraction_place;
2373 char *ptr;
2374 char *after_fraction;
2375 double absolute_value;
2376 int size;
2377

Callers 1

Calls 3

xmlXPathIsInfFunction · 0.85
xmlXPathIsNaNFunction · 0.85
log10Function · 0.50

Tested by

no test coverage detected