#### Archived

This topic is now archived and is closed to further replies.

# Floats over IP

This topic is 5644 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, I have a problem... I want to send a few floats, between the server and client. I do my socket reading/writting at an octet level, and, I am wondering, how long is a float, in octets. And, if the size of a float varies between machines... Thanks in advance. Height Map Editor

##### Share on other sites
a single precision floating point number is usually 4 bytes
You can always try sizeof(float) to be sure, that''s what it''s for. Since there is such a thing as IEEE fp standards, I doubt you will ever come across floats that are not 4 bytes... let me know if you do !

##### Share on other sites
Hmm, so a float is like an int?
Thank you very much.

Height Map Editor

##### Share on other sites
>>I doubt you will ever come across floats that are not 4 bytes... let me know if you do ! <<

Just curious, but does anyone know if the new 64-bit stuff on the horizon will change this at all?

-John

##### Share on other sites
The size of a float is sizeof(float).
The size of a double is sizeof(double).

IEEE 754 specifies an internal format of 32 and 64 bit floating point values, but there is no guarantee computer use it (ok, most modern machines do).

All C++ specifies is that long double is at least as accurate as double which is itself at least as accurate as float.

They could be all the same type - indeed, long double often is the same as double.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

##### Share on other sites
I know about sizeof(float) (duh!), but what I was wondering is if that differs from one architecture to another. My client/server are designed with portability in mind, and I would actually like it to be portable

Height Map Editor

##### Share on other sites
You''re more likely to have different sized ints than floats, since even on 64-bit architectures, floats and double are still usually 32- and 64- bits each.

If I had my way, I''d have all of you shot!

codeka.com - Just click it.

• 10
• 18
• 14
• 18
• 15