The following should work for IEEE */
| 129 | |
| 130 | /* The following should work for IEEE */ |
| 131 | __attribute__((unused)) static int PackDouble(const void *from, void *to) { |
| 132 | if (from == nullptr) { |
| 133 | return -1; |
| 134 | } |
| 135 | uint32_t length = sizeof(double); |
| 136 | const uchar *ptr = (uchar *)from; // NOLINT |
| 137 | double nr; |
| 138 | memcpy(&nr, ptr, length); |
| 139 | |
| 140 | uchar *tmp = (uchar *)to; // NOLINT |
| 141 | if (nr == 0.0) { /* Change to zero string */ |
| 142 | tmp[0] = (uchar)128; |
| 143 | memset(tmp + 1, 0, sizeof(nr) - 1); |
| 144 | } else { |
| 145 | uchar *ptr = (uchar *)&nr; // NOLINT |
| 146 | SwapDoubleBytes(tmp, ptr); |
| 147 | if (tmp[0] & 128) { /* Negative */ |
| 148 | uint32_t i; |
| 149 | for (i = 0; i < sizeof(nr); i++) tmp[i] = tmp[i] ^ (uchar)255; |
| 150 | } else { /* Set high and move exponent one up */ |
| 151 | uint16_t exp_part = |
| 152 | (((uint16_t)tmp[0] << 8) | (uint16_t)tmp[1] | (uint16_t)32768); |
| 153 | exp_part += (uint16_t)1 << (16 - 1 - DBL_EXP_DIG); |
| 154 | tmp[0] = (uchar)(exp_part >> 8); |
| 155 | tmp[1] = (uchar)exp_part; |
| 156 | } |
| 157 | } |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | This is the new algorithm. Similarly to the legacy format the input |