Boost logo

Boost Users :

Subject: Re: [Boost-users] Convert big endian to little endian (floating point values)
From: Aaron_Wright_at_[hidden]
Date: 2015-12-08 13:40:38


> From: Martin Vymazal <martin.vymazal_at_[hidden]>
> 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.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net