| 240 | } |
| 241 | |
| 242 | __attribute__((unused)) static int UnpackFloatingPoint( |
| 243 | const void *src, const size_t size, const int exp_digit, |
| 244 | const uchar *const zero_pattern, const uchar *const zero_val, |
| 245 | void (*swap_func)(uchar *, const uchar *), void *dst) { |
| 246 | const uchar *const from = (uchar *)src; // NOLINT |
| 247 | uchar *const udst = (uchar *)dst; // NOLINT |
| 248 | if (from == nullptr) { |
| 249 | return -1; |
| 250 | } |
| 251 | /* Check to see if the value is zero */ |
| 252 | if (memcmp(from, zero_pattern, size) == 0) { |
| 253 | memcpy(udst, zero_val, size); |
| 254 | return 0; |
| 255 | } |
| 256 | // use a temporary buffer to make byte-swapping easier later |
| 257 | uchar tmp[8]; |
| 258 | memcpy(tmp, from, size); |
| 259 | if (tmp[0] & 0x80) { |
| 260 | // If the high bit is set the original value was positive so |
| 261 | // remove the high bit and subtract one from the exponent. |
| 262 | uint16_t exp_part = ((uint16_t)tmp[0] << 8) | (uint16_t)tmp[1]; |
| 263 | exp_part &= 0x7FFF; // clear high bit; |
| 264 | exp_part -= (uint16_t)1 |
| 265 | << (16 - 1 - exp_digit); // subtract from exponent |
| 266 | tmp[0] = (uchar)(exp_part >> 8); |
| 267 | tmp[1] = (uchar)exp_part; |
| 268 | } else { |
| 269 | // Otherwise the original value was negative and all bytes have been |
| 270 | // negated. |
| 271 | for (size_t ii = 0; ii < size; ii++) tmp[ii] ^= 0xFF; |
| 272 | } |
| 273 | // On little-endian, swap the bytes around |
| 274 | swap_func(udst, tmp); |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | Function of type rdb_index_field_unpack_t |
no outgoing calls
no test coverage detected