Taken from OpenEXR
| 155 | |
| 156 | // Taken from OpenEXR |
| 157 | INLINE ILuint ILAPIENTRY ilHalfToFloat (ILushort y) { |
| 158 | |
| 159 | int s = (y >> 15) & 0x00000001; |
| 160 | int e = (y >> 10) & 0x0000001f; |
| 161 | int m = y & 0x000003ff; |
| 162 | |
| 163 | if (e == 0) |
| 164 | { |
| 165 | if (m == 0) |
| 166 | { |
| 167 | // |
| 168 | // Plus or minus zero |
| 169 | // |
| 170 | |
| 171 | return s << 31; |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | // |
| 176 | // Denormalized number -- renormalize it |
| 177 | // |
| 178 | |
| 179 | while (!(m & 0x00000400)) |
| 180 | { |
| 181 | m <<= 1; |
| 182 | e -= 1; |
| 183 | } |
| 184 | |
| 185 | e += 1; |
| 186 | m &= ~0x00000400; |
| 187 | } |
| 188 | } |
| 189 | else if (e == 31) |
| 190 | { |
| 191 | if (m == 0) |
| 192 | { |
| 193 | // |
| 194 | // Positive or negative infinity |
| 195 | // |
| 196 | |
| 197 | return (s << 31) | 0x7f800000; |
| 198 | } |
| 199 | else |
| 200 | { |
| 201 | // |
| 202 | // Nan -- preserve sign and significand bits |
| 203 | // |
| 204 | |
| 205 | return (s << 31) | 0x7f800000 | (m << 13); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // |
| 210 | // Normalized number |
| 211 | // |
| 212 | |
| 213 | e = e + (127 - 15); |
| 214 | m = m << 13; |
no outgoing calls
no test coverage detected