On 2015-12-08 19:40, Aaron_Wright@selinc.com wrote:
From: Martin Vymazal
Hello, I am trying to convert a floating point value from big endian to little endian, but the code below does not compile:
double x = 10.0;
const double x_big_endian = boost::endian::native_to_big(x); boost::endian::native_to_big_inplace(x);
Be very careful how you swap floats. They aren't like integer data types where the swapped representation can fit nicely into the same type. Not all swapped floats are valid floats, and you'll find that the bits will be messaged into a valid float, thus changing your value without telling you. You can only swap a float into an integer. You can't swap a float into a float.
Hi, ok, here's the whole story. We have a code that computes some data, compresses them through zlib and saves as binary. We also use our own utility to postprocess the compressed file and convert it to human-readable format. What happened recently is that the code ran on a big-endian machine and since zlib preserves the endian-ess of the data, it generated a binary with big-endian doubles. We would like to have the possibility of bringing that file on a little-endian machine (say user's laptop) and postprocess there, instead of doing everything on the big-endian machine. Do you have an alternative suggestion how to approach this problem? Let's assume that writing the output data in any other format than the current one is not possible. I am also still interested in knowing whether boost (1.59) supports conversions between endian representations of floating-point values. Martin