[Home] [Groups] - Message: [Prev in Group] [Next in Group]

nu.kanga.list.mud-dev

7167: [MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?

[Full Header] [Plain Text]
From: "Adam J. Thornton" <adam@phoenix.Princeton.EDU>
Newsgroups: nu.kanga.list.mud-dev
Date: Mon, 7 Sep 1998 12:05:57 -0400
References: [1] [2] <-newest
Organization: Kanga.Nu
On Mon, Sep 07, 1998 at 07:52:41AM -0600, T. Alexander Popiel wrote:
> In message:  <Pine.LNX.3.96.980906215952.30075A-100000@shamen.cyberhighway.net>
> >What is the standard way (if there is one) to encode floating
> >point numbers (double too I guess) into bytes for transport accross
> >the network.
> >It would seem like there would be a method to do this somewhere!
> Standard is to send raw IEEE format across the wire; just about
> everyone uses IEEE internally these days, and those who don't
> know how to convert, so they can talk with those that do.

You'd clearly use htonl() for ints.  You could use fcvt() or ecvt().  Or
maybe even sprintf().  All of these are probably a little more portable, but
much slower, and when you're recovering the number with sscanf() you need
to worry about precision.

Adam
--
adam@princeton.edu 
"There's a border to somewhere waiting, and a tank full of time." - J. Steinman