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

Adam J. Thornton adam at phoenix.Princeton.EDU
Mon Sep 7 12:05:57 CEST 1998


On Mon, Sep 07, 1998 at 07:52:41AM -0600, T. Alexander Popiel wrote:
> In message:  <Pine.LNX.3.96.980906215952.30075A-100000 at 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 at princeton.edu 
"There's a border to somewhere waiting, and a tank full of time." - J. Steinman




More information about the mud-dev-archive mailing list