My program reads into 4 bytes an IEEE 754 floating point number from a file. I need to portable convert those bytes to my C compilers float type. In other words I need a fun
If your implementation can guarantee correct endianness:
float raw2ieee(uint8_t *raw)
{
// either
union {
uint8_t bytes[4];
float fp;
} un;
memcpy(un.bytes, raw, 4);
return un.fp;
// or, as seen in the fast inverse square root:
return *(float *)raw;
}