views:

124

answers:

3

Hi

I'm writing a client and a server for a realtime offshore simulator, and, as I have to send a lot of data through a socket, I'm using binary data to maximize the ammount of data I can send. I already know about integers endianness, and how to use htonl and ntohl to circumvent endianness issues, but my application, as almost all simulation software, deals with a lot of floats.

My question is: Is there some issue of endianness whean dealing with binary formats of floating point numbers? I know that all the machines where my code will run use IEEE implementation of floating points, but is there some endianness issue when dealing with floats?

Since I only have access to machines with the same endian, I cannot test this by myself. So, I'll be glad if someone can help me with this.

Thanks in advance.

A: 

Yes, floating point can be endianess dependent. See http://stackoverflow.com/questions/2782725/converting-float-values-from-big-endian-to-little-endian/2782742#2782742 for info, be sure to read the comments.

gbrandt
Thanks for the link.
cake
+2  A: 

According to Wikipedia,

Floating-point and endianness

On some machines, while integers were represented in little-endian form, floating point numbers were represented in big-endian form. Because there are many floating point formats, and a lack of a standard "network" representation, no standard for transferring floating point values has been made. This means that floating point data written on one machine may not be readable on another, and this is the case even if both use IEEE 754 floating point arithmetic since the endianness of the memory representation is not part of the IEEE specification.

Daniel Pryden
A: 

There is no such thing as floating point endianness or integer endianness etc. Its just binary representation endianness. Either a machine is little-endian, or its big-endian. Which means that it will either represent the MSb/MSB in the binary representation of any datatype as its first bit/byte or last bit/byte. Thats it.

Thanks for the clarification on Endianness meaning. I wasn't sure how MSB order was defined in the case of floating point numbers.
cake
Would the downvoter care to explain themself? I though this post nicely clarified the topic of endianess, and was in line with my own understanding of it.
csj
While I didn't downvote, it might have been because the statement isn't actually true. There have been systems where the FPU expected a different byte order than the rest of the system did, in which case there would be "floating point endianness" and "integer endianness." I don't *think* its much of an issue on modern architectures, though, so as a general rule you're likely okay to ignore this distinction.
Dennis Zickefoose
@Dennis Thank you. I did not know that systems existed where the FPU used a different endianness.
csj
Dennis thanks for the clarification. However, I fail to understand the relationship between FPU and network transactions. Network transactions will be based on the system endianness, which would be independent of the FPU endianness, AFAIunderstand. Can you please correct me if I'm wrong.Thanks.