Floats over IP

Started by
5 comments, last by Raduprv 21 years, 4 months ago
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
Advertisement
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 !
Hmm, so a float is like an int?
Thank you very much.

Height Map Editor
>>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
- John
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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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
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.

This topic is closed to new replies.

Advertisement