[Home] [Groups] - Message: [Prev in Group] [Next in Group]
7179: [MUD-Dev] Re: [CODE QUESTION] How to encode floats into bytes?
[Full Header] [Plain Text]
From: Adam Wiggins <adam@angel.com>
Newsgroups: nu.kanga.list.mud-dev
Date: Tue, 8 Sep 1998 12:30:15 -0700 (PDT)
References: [1]
Organization: Kanga.Nu
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.