Search code examples
cserializationincludeaixieee-754

AIX equivalent of ieee754.h


I wrote some C code that serializes certain values into a file that is subsequently deserialized (using custom code) in Java on another machine.

Among values I'm serializing are 64-bit double precision floating point real numbers. When I wrote the code, it was going to be compiled and run only on Linux with a gcc available to compile it. I used ieee754.h to get access to all parts of the value, as per IEEE 754 standard, and write those parts to a file. On Java end, I would simply use Double.longBitsToDouble(long) to reassemble the value.

The problem is that I've been asked to make the code able to compile and run on AIX 5.3, using xlc 10.

Is there any equivalent of ieee754.h on AIX?


Solution

  • Short of endianness issues, IEEE754 is a fixed format. There's no need for a system header to tell you what it looks like. Just do something like:

    uint64_t rep;
    double x;
    memcpy(&rep, &x, sizeof rep);
    

    You might want to include some code for conditionally byte-order-swapping the result if you're on a platform where you have to do that, but as far as I know, AIX is not going to be one of those.