* xmlXPathFormatNumber: * @number: number to format * @buffer: output buffer * @buffersize: size of output buffer * * Convert the number into a string representation. */
| 5798 | * Convert the number into a string representation. |
| 5799 | */ |
| 5800 | static void |
| 5801 | xmlSchemaFormatFloat(double number, char buffer[], int buffersize) |
| 5802 | { |
| 5803 | switch (xmlXPathIsInf(number)) { |
| 5804 | case 1: |
| 5805 | if (buffersize > (int)sizeof("INF")) |
| 5806 | snprintf(buffer, buffersize, "INF"); |
| 5807 | break; |
| 5808 | case -1: |
| 5809 | if (buffersize > (int)sizeof("-INF")) |
| 5810 | snprintf(buffer, buffersize, "-INF"); |
| 5811 | break; |
| 5812 | default: |
| 5813 | if (xmlXPathIsNaN(number)) { |
| 5814 | if (buffersize > (int)sizeof("NaN")) |
| 5815 | snprintf(buffer, buffersize, "NaN"); |
| 5816 | } else if (number == 0) { |
| 5817 | snprintf(buffer, buffersize, "0.0E0"); |
| 5818 | } else { |
| 5819 | /* 3 is sign, decimal point, and terminating zero */ |
| 5820 | char work[DBL_DIG + EXPONENT_DIGITS + 3]; |
| 5821 | int integer_place, fraction_place; |
| 5822 | char *ptr; |
| 5823 | char *after_fraction; |
| 5824 | double absolute_value; |
| 5825 | int size; |
| 5826 | |
| 5827 | absolute_value = fabs(number); |
| 5828 | |
| 5829 | /* |
| 5830 | * Result is in work, and after_fraction points |
| 5831 | * just past the fractional part. |
| 5832 | * Use scientific notation |
| 5833 | */ |
| 5834 | integer_place = DBL_DIG + EXPONENT_DIGITS + 1; |
| 5835 | fraction_place = DBL_DIG - 1; |
| 5836 | snprintf(work, sizeof(work),"%*.*e", |
| 5837 | integer_place, fraction_place, number); |
| 5838 | after_fraction = strchr(work + DBL_DIG, 'e'); |
| 5839 | /* Remove fractional trailing zeroes */ |
| 5840 | ptr = after_fraction; |
| 5841 | while (*(--ptr) == '0') |
| 5842 | ; |
| 5843 | if (*ptr != '.') |
| 5844 | ptr++; |
| 5845 | while ((*ptr++ = *after_fraction++) != 0); |
| 5846 | |
| 5847 | /* Finally copy result back to caller */ |
| 5848 | size = strlen(work) + 1; |
| 5849 | if (size > buffersize) { |
| 5850 | work[buffersize - 1] = 0; |
| 5851 | size = buffersize; |
| 5852 | } |
| 5853 | memmove(buffer, work, size); |
| 5854 | } |
| 5855 | break; |
| 5856 | } |
| 5857 | } |
nothing calls this directly
no test coverage detected