Does a float need to be converted to network order?

Discussion in 'C++' started by sidewinder, Jun 23, 2003.

  1. sidewinder

    sidewinder Guest

    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))
    sidewinder, Jun 23, 2003
    #1
    1. Advertising

  2. sidewinder

    Adie Guest

    Dan Cernat wrote:
    >"sidewinder" <> 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.
    Adie, Jun 24, 2003
    #2
    1. Advertising

  3. sidewinder

    Adie Guest

    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.
    Adie, Jun 24, 2003
    #3
  4. sidewinder

    Dan Cernat Guest

    "sidewinder" <> wrote in message
    news:5ALJa.4403$...
    > 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
    Dan Cernat, Jun 24, 2003
    #4
  5. sidewinder

    JeffK. Guest

    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
    JeffK., Jun 24, 2003
    #5
  6. sidewinder

    Adie Guest

    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.
    Adie, Jun 24, 2003
    #6
  7. 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
    Alexander Terekhov, Jun 24, 2003
    #7
  8. Alexander Terekhov, Jun 25, 2003
    #8
  9. 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...

    ;-)
    Steve Coleman, Jun 25, 2003
    #9
  10. "Alexander Terekhov" <> schrieb im Newsbeitrag
    news:...
    >
    > 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
    Karl Heinz Buchegger, Jun 26, 2003
    #10
  11. Karl Heinz Buchegger wrote:
    >
    > "Alexander Terekhov" <> schrieb im Newsbeitrag
    > news:...
    > >
    > > 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. ;-)
    Alexander Terekhov, Jun 26, 2003
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    7
    Views:
    6,238
    Roedy Green
    May 10, 2004
  2. Jim West
    Replies:
    4
    Views:
    1,400
    Jeff Schwab
    Jan 16, 2004
  3. bd
    Replies:
    0
    Views:
    605
  4. vlsidesign

    0 converted to 0.0 for float variable?

    vlsidesign, Nov 8, 2007, in forum: C Programming
    Replies:
    6
    Views:
    324
    jacob navia
    Nov 9, 2007
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,505
    James Kanze
    Oct 8, 2009
Loading...

Share This Page