[MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?
Adam Wiggins
adam at angel.com
Tue Sep 8 12:30:15 CEST 1998
On Mon, 7 Sep 1998, Ben Greear wrote:
> I'm perfectly happy sending bits across in IEEE 754 format. However,
> I don't know how to get the bits. Can you bit-mask floats? Basically,
> I need a way to grab the mantissa and the exponent as either raw bits
> or integers. Then I can pack it according to the IEEE standard.
>
> Maybe I'm being too complicated. Maybe something like this would encode:
>
> file_descriptor f; //assume it's connected appropriately.
> float f = 42.5;
> char* bytes = (char*)(&f);
> write(f, bytes, 0, 4); //think those args are right..
>
> This ignores network order, but I can deal with that.
Not only that, but if you decide to compile with -ffast-math one day, you
may get some funny results.
More information about the mud-dev-archive
mailing list