* Print special case values for infinities and NaNs. * The output string is always NUL terminated and the string length (not * including the NUL) is returned. */
| 2109 | * including the NUL) is returned. |
| 2110 | */ |
| 2111 | static npy_uint32 |
| 2112 | PrintInfNan(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa, |
| 2113 | npy_uint32 mantissaHexWidth, char signbit) |
| 2114 | { |
| 2115 | npy_uint32 maxPrintLen = bufferSize-1; |
| 2116 | npy_uint32 pos = 0; |
| 2117 | |
| 2118 | DEBUG_ASSERT(bufferSize > 0); |
| 2119 | |
| 2120 | /* Check for infinity */ |
| 2121 | if (mantissa == 0) { |
| 2122 | npy_uint32 printLen; |
| 2123 | |
| 2124 | /* only print sign for inf values (though nan can have a sign set) */ |
| 2125 | if (signbit == '+') { |
| 2126 | if (pos < maxPrintLen-1) { |
| 2127 | buffer[pos++] = '+'; |
| 2128 | } |
| 2129 | } |
| 2130 | else if (signbit == '-') { |
| 2131 | if (pos < maxPrintLen-1) { |
| 2132 | buffer[pos++] = '-'; |
| 2133 | } |
| 2134 | } |
| 2135 | |
| 2136 | /* copy and make sure the buffer is terminated */ |
| 2137 | printLen = (3 < maxPrintLen - pos) ? 3 : maxPrintLen - pos; |
| 2138 | memcpy(buffer + pos, "inf", printLen); |
| 2139 | buffer[pos + printLen] = '\0'; |
| 2140 | return pos + printLen; |
| 2141 | } |
| 2142 | else { |
| 2143 | /* copy and make sure the buffer is terminated */ |
| 2144 | npy_uint32 printLen = (3 < maxPrintLen - pos) ? 3 : maxPrintLen - pos; |
| 2145 | memcpy(buffer + pos, "nan", printLen); |
| 2146 | buffer[pos + printLen] = '\0'; |
| 2147 | |
| 2148 | /* |
| 2149 | * For numpy we ignore unusual mantissa values for nan, but keep this |
| 2150 | * code in case we change our mind later. |
| 2151 | * |
| 2152 | * // append HEX value |
| 2153 | * if (maxPrintLen > 3) { |
| 2154 | * printLen += PrintHex(buffer+3, bufferSize-3, mantissa, |
| 2155 | * mantissaHexWidth); |
| 2156 | * } |
| 2157 | */ |
| 2158 | |
| 2159 | return pos + printLen; |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | /* |
| 2164 | * The functions below format a floating-point numbers stored in particular |
no outgoing calls
no test coverage detected