| 96 | } |
| 97 | |
| 98 | __attribute__((unused)) static int PackFloat(const void *from, void *to) { |
| 99 | if (from == nullptr) { |
| 100 | return -1; |
| 101 | } |
| 102 | uint32_t length = sizeof(float); |
| 103 | const uchar *ptr = (uchar *)from; // NOLINT |
| 104 | float nr; |
| 105 | memcpy(&nr, ptr, length); |
| 106 | |
| 107 | uchar *tmp = (uchar *)to; // NOLINT |
| 108 | if (nr == (float)0.0) { // NOLINT |
| 109 | /* Change to zero string */ |
| 110 | tmp[0] = (uchar)128; |
| 111 | memset(tmp + 1, 0, length - 1); |
| 112 | } else { |
| 113 | SwapFloatBytes(tmp, ptr); |
| 114 | if (tmp[0] & 128) { |
| 115 | /* Negative */ |
| 116 | uint32_t i; |
| 117 | for (i = 0; i < sizeof(nr); i++) |
| 118 | tmp[i] = (uchar)(tmp[i] ^ (uchar)255); |
| 119 | } else { |
| 120 | uint16_t exp_part = |
| 121 | (((uint16_t)tmp[0] << 8) | (uint16_t)tmp[1] | (uint16_t)32768); |
| 122 | exp_part += (uint16_t)1 << (16 - 1 - FLT_EXP_DIG); |
| 123 | tmp[0] = (uchar)(exp_part >> 8); |
| 124 | tmp[1] = (uchar)exp_part; |
| 125 | } |
| 126 | } |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | /* The following should work for IEEE */ |
| 131 | __attribute__((unused)) static int PackDouble(const void *from, void *to) { |