By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,612 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,612 IT Pros & Developers. It's quick & easy.

Does a float need to be converted to network order?

P: n/a
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))
Jul 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a

"sidewinder" <sp**@nospam.com> wrote in message
news:5A****************@rwcrnsc51.ops.asp.att.net. ..
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
Jul 19 '05 #2

P: n/a
Dan Cernat wrote:
"sidewinder" <sp**@nospam.com> wrote in message

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?


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.
Jul 19 '05 #3

P: n/a
Thomas Matthews wrote:
sidewinder wrote:
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))


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.
Jul 19 '05 #4

P: n/a
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
Jul 19 '05 #5

P: n/a
Karl Heinz Buchegger wrote:
Adie wrote:

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


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.
Jul 19 '05 #6

P: n/a

Adie wrote:

Karl Heinz Buchegger wrote:
Adie wrote:

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


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.


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

regards,
alexander.

--
7.949928895127363e-275
Jul 19 '05 #7

P: n/a

Karl Heinz Buchegger wrote:
[...]
And yes: I have already been biten by trying to pass floating
point values in a binary form (PC to VAX, 12 years ago)


http://h18003.www1.hp.com/hps/ipf-en...g_point_wp.pdf

regards,
alexander.

--
float x = -1.5e38; float y = +1.5e38;
std::cout << (x + y) + 1.0 << " != "
<< x + (y + 1.0) << "\n";
Jul 19 '05 #8

P: n/a
Karl Heinz Buchegger wrote:
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...

;-)


Jul 19 '05 #9

P: n/a

"Alexander Terekhov" <te******@web.de> schrieb im Newsbeitrag
news:3E***************@web.de...

Steve Coleman wrote:

Karl Heinz Buchegger wrote:
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. ...


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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #10

P: n/a

Karl Heinz Buchegger wrote:

"Alexander Terekhov" <te******@web.de> schrieb im Newsbeitrag
news:3E***************@web.de...

Steve Coleman wrote:

Karl Heinz Buchegger wrote:

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


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.


Karl, only for you.

http://www.alphaworks.ibm.com/tech/decNumber

regards,
alexander.

P.S. And, BTW, it's not really expensive. ;-)
Jul 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.