MUD-Dev
mailing list archive

[ Other Periods  | Other mailing lists  | Search  ]

Date:  [ Previous  | Next  ]      Thread:  [ Previous  | Next  ]      Index:  [ Author  | Date  | Thread  ]

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



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.





[ Other Periods  | Other mailing lists  | Search  ]