----------------------------------------------------- Float-to-half conversion -- general case, including zeroes, denormalized numbers and exponent overflows. -----------------------------------------------------
| 27 | // zeroes, denormalized numbers and exponent overflows. |
| 28 | //----------------------------------------------------- |
| 29 | ILushort ILAPIENTRY ilFloatToHalf(ILuint i) { |
| 30 | // |
| 31 | // Our floating point number, f, is represented by the bit |
| 32 | // pattern in integer i. Disassemble that bit pattern into |
| 33 | // the sign, s, the exponent, e, and the significand, m. |
| 34 | // Shift s into the position where it will go in in the |
| 35 | // resulting half number. |
| 36 | // Adjust e, accounting for the different exponent bias |
| 37 | // of float and half (127 versus 15). |
| 38 | // |
| 39 | |
| 40 | register int s = (i >> 16) & 0x00008000; |
| 41 | register int e = ((i >> 23) & 0x000000ff) - (127 - 15); |
| 42 | register int m = i & 0x007fffff; |
| 43 | |
| 44 | // |
| 45 | // Now reassemble s, e and m into a half: |
| 46 | // |
| 47 | |
| 48 | if (e <= 0) |
| 49 | { |
| 50 | if (e < -10) |
| 51 | { |
| 52 | // |
| 53 | // E is less than -10. The absolute value of f is |
| 54 | // less than HALF_MIN (f may be a small normalized |
| 55 | // float, a denormalized float or a zero). |
| 56 | // |
| 57 | // We convert f to a half zero. |
| 58 | // |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | // |
| 64 | // E is between -10 and 0. F is a normalized float, |
| 65 | // whose magnitude is less than HALF_NRM_MIN. |
| 66 | // |
| 67 | // We convert f to a denormalized half. |
| 68 | // |
| 69 | |
| 70 | m = (m | 0x00800000) >> (1 - e); |
| 71 | |
| 72 | // |
| 73 | // Round to nearest, round "0.5" up. |
| 74 | // |
| 75 | // Rounding may cause the significand to overflow and make |
| 76 | // our number normalized. Because of the way a half's bits |
| 77 | // are laid out, we don't have to treat this case separately; |
| 78 | // the code below will handle it correctly. |
| 79 | // |
| 80 | |
| 81 | if (m & 0x00001000) |
| 82 | m += 0x00002000; |
| 83 | |
| 84 | // |
| 85 | // Assemble the half from s, e (zero) and m. |
| 86 | // |
nothing calls this directly
no test coverage detected