Does a float need to be converted to network order?

S

sidewinder

If it does, and it is going between a little endian and a big endian
machines can we byte swap it as an int or long? Or does the mantissa or
exponent cross 2 byte boundarys?

Can I just call htonl ( (long) floatvalue))
 
A

Adie

Dan said:
The right question would be: 'does a float need to be converted to network
order if one want to <insert your action here> ?'

If you don't tell us what you want to do with it, what can we tell you.

Does one need to add two integers?

Excuse my ignorance, but why not just send the value as a string and
convert? No endianness to worry about and isnt that how the majority of
protocols operate, with string literals.
 
A

Adie

Thomas said:
No. float types can work perfectly well without being converted,
just use the appropriate math libraries and output functions.

But then, if you were asking about networking stuff, which is
platform dependent, you will have to ask in a newsgroup that
discusses your platform. Networking stuff is not a part
of the _standard_ C++ language and thus not discussed here.

you'll be so fucking bugged out when byte ordering is added to the
standard.
 
D

Dan Cernat

sidewinder said:
If it does, and it is going between a little endian and a big endian
machines can we byte swap it as an int or long? Or does the mantissa or
exponent cross 2 byte boundarys?

Can I just call htonl ( (long) floatvalue))

The right question would be: 'does a float need to be converted to network
order if one want to <insert your action here> ?'

If you don't tell us what you want to do with it, what can we tell you.

Does one need to add two integers?


Dan
 
J

JeffK.

Look up the topic XDR / RPC -- its a C/C++ like language that addresses
data transfer between computers and eliminates the need to worry about
such
issues.

Hope this helps,

JeffK
 
A

Adie

Karl said:
In this specific case this will never happen.
Sending float's (or double's) in binary to a different
machine is asking for troubles. Byte ordering is the
least of your problems.

Ok Karl, I'll take your word for it.
 
A

Alexander Terekhov

Adie said:
Ok Karl, I'll take your word for it.

Take it with a pinch of salt. Little Karl never heard of IEEE 754,
I guess.

regards,
alexander.
 
S

Steve Coleman

Karl said:
Please show me in the C++ standard where it is mentioned
that every C++ implementation has to use that.

I haven't read the 'C++ standard' on this issue but I believe this is a
networking library question and thus the question should be asked in
another group.

But having to deal with this very issue on a daily basis I suggest that
they look into XDR or CDR as an answer to the origional problem. Any OS
worth is weight will have an implimentation of one or both of these (and
you can download/compile it if its not) and the libraries 'standard'
dictates that the library will perform the correct endian conversion on
both ends of the connection for all defined types, because thats what
its for!

Now it we wanted to discuss C++ wrappers for the network libraries...

;-)
 
K

Karl Heinz Buchegger

Alexander Terekhov said:
Both XDR and CDR use >>THE IEEE 754<< for representations.

Ahh. Now that's really usefull information. Not that I am
involved into network tasks. But those things could be
usefull some day. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top