Here you can find the source of toFloatRawBits(int i)
Parameter | Description |
---|---|
y | the raw bits of a 16-bit half float |
public static int toFloatRawBits(int i)
//package com.java2s; public class Main { /**//from w ww . ja va 2s . c o m * Delta between bias of 32-bit float and 16-bit half float. (127 - 15) * * */ public static int BIAS_DELTA = 127 - 15; /** * Converts the raw bits of a 16-bit half float to the raw bits * of a 32-bit float. * * @param y the raw bits of a 16-bit half float * @return the raw bits of a 32-bit float * * */ public static int toFloatRawBits(int i) { int s = (i >> 15) & 0x1; int e = (i >> 10) & 0x1f; int m = i & 0x3ff; if (e == 0) { if (m == 0) { // plus or minus zero return s << 31; } else { // denormalized number -- renormalize it while ((m & 0x400) == 0) { m <<= 1; e -= 1; } e += 1; // restore e offset with 1 m &= ~0x400; // get rid of the implicit leading 1 } } else if (e == 31) { if (m == 0) { // positive or negative infinity return (s << 31) | 0x7f800000; } else { // NaN -- preserve sign and significand bits return (s << 31) | 0x7f800000 | (m << 13); } } // normalized number e = e + BIAS_DELTA; m = m << 13; // Assemble s, e and m. return (s << 31) | (e << 23) | m; } }