I need to read in a large file full of half-precision (binary16) floating point numbers.
I have two questions:
1) Is there a clean way to do this directly that I'm missing (e.g. "read(fstream, Float16, size)" where Float16 exists)?
2) If not, what's the cleanest way to create floating point numbers from raw bits or convert these values manually? (I.e., I don't want 0x00000010 to be converted to 16.0, but rather the appropriate 32-bit floating point value represented by those bits.)
My current plan, in the worst case, is to write a pretty nasty hack that reads the values in as an array of Uint16s. Then, I'll create an array of Uint32s whose bits correspond to the Float32 equivalents of all my half-precision floats by conducting the appropriate bit manipulations. Lastly, I'll convert the array of Uint32s to a pointer to Uint32s, convert the pointer to a pointer to Float32s, and then convert that back to an array of Float32s. :/
I don't want to create the Floats using any floating point operations, like converting the significand to a Float and then manually multiplying by 2^exp etc., for example, because I don't want to introduce any additional floating point error in the numbers.
Thanks.