| 167 | const ULONG OFF_nan = 1; |
| 168 | |
| 169 | void make(ULONG* key, |
| 170 | const unsigned pMax, const int bias, const unsigned decSize, |
| 171 | unsigned char* coeff, int sign, int exp, decClass cl) |
| 172 | { |
| 173 | ULONG offset = 0; |
| 174 | |
| 175 | // special cases |
| 176 | switch(cl) |
| 177 | { |
| 178 | case DEC_CLASS_SNAN: |
| 179 | offset = OFF_snan; |
| 180 | break; |
| 181 | case DEC_CLASS_QNAN: |
| 182 | offset = OFF_nan; |
| 183 | break; |
| 184 | case DEC_CLASS_NEG_INF: |
| 185 | offset = OFF_inf; |
| 186 | sign = DECFLOAT_Sign; |
| 187 | break; |
| 188 | case DEC_CLASS_POS_INF: |
| 189 | offset = OFF_inf; |
| 190 | sign = 0; |
| 191 | break; |
| 192 | default: |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | if (offset) // special value |
| 197 | { |
| 198 | unsigned dig = decSize / sizeof(ULONG); |
| 199 | fb_assert(!(decSize % sizeof(ULONG))); |
| 200 | while (dig--) |
| 201 | *key++ = sign ? ~MAX_SLONG : MAX_SLONG; |
| 202 | *key = MAX_SLONG - offset; |
| 203 | if (sign) |
| 204 | *key = ~*key; |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | // normalize coeff & exponent |
| 209 | unsigned dig = digits(pMax, coeff, exp); |
| 210 | |
| 211 | // exponent bias and sign |
| 212 | if (!dig) |
| 213 | { |
| 214 | exp = 0; |
| 215 | sign = 0; |
| 216 | } |
| 217 | else |
| 218 | { |
| 219 | exp += (bias + 2); |
| 220 | if (sign) |
| 221 | exp = -exp; |
| 222 | } |
| 223 | |
| 224 | *key++ = exp; |
| 225 | |
| 226 | // convert to SLONG |
no test coverage detected