Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating point Endianness?

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 amount 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 when 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.

like image 368
cake Avatar asked May 31 '10 17:05

cake


People also ask

Are floats affected by endianness?

Yes, floating point can be endianess dependent.

Are floats big or little endian?

Integers and floating-point numbers don't care about endianness; they're just multi-byte values. Likewise, endianness doesn't care about whether it's an int or a float. It just stores the bytes in a particular order. @HansPassant "The 4 bytes are just stored in reverse order.

How are floats stored in little endian?

Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first (at the lowest storage address). Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first.

What is the point of endianness?

Going back to the Wikipedia article, the stated advantage of big-endian numbers is that the size of the number can be more easily estimated because the most significant digit comes first.


1 Answers

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.

like image 107
Daniel Pryden Avatar answered Sep 29 '22 13:09

Daniel Pryden