| 313 | var _int32View = new Int32Array(_floatView.buffer); |
| 314 | |
| 315 | function floatToHalf(float) { |
| 316 | _floatView[0] = float; |
| 317 | var f = _int32View[0]; |
| 318 | |
| 319 | var sign = (f >> 31) & 0x0001; |
| 320 | var exp = (f >> 23) & 0x00ff; |
| 321 | var frac = f & 0x007fffff; |
| 322 | |
| 323 | var newExp; |
| 324 | if (exp == 0) { |
| 325 | newExp = 0; |
| 326 | } else if (exp < 113) { |
| 327 | newExp = 0; |
| 328 | frac |= 0x00800000; |
| 329 | frac = frac >> (113 - exp); |
| 330 | if (frac & 0x01000000) { |
| 331 | newExp = 1; |
| 332 | frac = 0; |
| 333 | } |
| 334 | } else if (exp < 142) { |
| 335 | newExp = exp - 112; |
| 336 | } else { |
| 337 | newExp = 31; |
| 338 | frac = 0; |
| 339 | } |
| 340 | |
| 341 | return (sign << 15) | (newExp << 10) | (frac >> 13); |
| 342 | } |
| 343 | |
| 344 | function packHalf2x16(x, y) { |
| 345 | return (floatToHalf(x) | (floatToHalf(y) << 16)) >>> 0; |