473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Does a float need to be converted to network order?

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
10 11155

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

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

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

"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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Vineet Jain | last post by:
int('2.1') does not work while int(float('2.1')) does. If int can covert a float object then there is no reason why a float string should not be converted too. When I do int('2.1') I get the...
14
by: Glen Able | last post by:
Should it be possible to create a custom class, 'Float', which would behave as a drop-in replacement for the builtin float type? As mentioned in another thread, I once tried this in rather a...
5
by: Kubik | last post by:
Hi! Let's see, we got: float var=4.6f; //as we know 414/4.6 shoud be equal to 90 but Math.Ceiling(414/var) gives us 91 but (414/var).ToString() prints '90'.
16
by: Enekajmer | last post by:
Hi, 1 int main() 2 { 3 float a = 17.5; 4 printf("%d\n", a); 5 printf("%d\n", *(int *)&a); 6 return 0; 7 }
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
6
by: vlsidesign | last post by:
Newbie question: 0 converted to 0.0 for float variable? If I have the following code, float myTotal; myTotal = 0; will C automatically add a decimal point and at least one zero to the right...
0
by: Timothy Grant | last post by:
That's because s IS a string. It's not been converted to a float. In : s = '3.1415' In : n = float(s) In : type(s) Out: <type 'str'> In : type(n) Out: <type 'float'> Why are you avoiding...
3
by: c.lang.myself | last post by:
#include <stdio.h> float puzzle( float inp ) { const float ths = 1.5F; const long k = 21*76069667; float a, b; int c;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.