[MUD-Dev] Network float format (RFC 1014)

J C Lawrence claw at kanga.nu
Wed Oct 14 22:42:10 CEST 1998


Some time back there was a thread on the network format to use for
floating point values (Ben?), with the observation that there was not
equivalent to htonl() for such.  The concern was for implementing
client protocols where coordinate data exchanges might enclude
floating point values.

RFC 1014, "XDR: External Data Representation Standard" which can be
found at

  http://www.pasteur.fr/other/computer/RFC/10xx/1014

has some to say on this area, and in fact addresses the general area
of transmission formats rather thoroughly:

--<cut>--

3.6 Floating-point

   The standard defines the floating-point data type "float" (32 bits or
   4 bytes).  The encoding used is the IEEE standard for normalized
   single-precision floating-point numbers [3].  The following three
   fields describe the single-precision floating-point number:

      S: The sign of the number.  Values 0 and 1 represent positive and
         negative, respectively.  One bit.

      E: The exponent of the number, base 2.  8 bits are devoted to this
         field.  The exponent is biased by 127.

      F: The fractional part of the number's mantissa, base 2.  23 bits
         are devoted to this field.

   Therefore, the floating-point number is described by:

         (-1)**S * 2**(E-Bias) * 1.F

   It is declared as follows:
         float identifier;

         +-------+-------+-------+-------+
         |byte 0 |byte 1 |byte 2 |byte 3 |              SINGLE-PRECISION
         S|   E   |           F          |         FLOATING-POINT NUMBER
         +-------+-------+-------+-------+
         1|<- 8 ->|<-------23 bits------>|
         <------------32 bits------------>

   Just as the most and least significant bytes of a number are 0 and 3,
   the most and least significant bits of a single-precision floating-
   point number are 0 and 31.  The beginning bit (and most significant
   bit) offsets of S, E, and F are 0, 1, and 9, respectively.  Note that
   these numbers refer to the mathematical positions of the bits, and
   NOT to their actual physical locations (which vary from medium to
   medium).

   The EEE specifications should be consulted concerning the encoding
   for signed zero, signed infinity (overflow), and denormalized numbers
   (underflow) [3].  According to IEEE specifications, the "NaN" (not a
   number) is system dependent and should not be used externally.

--<cut>--

With further text on doubles, fixed lenth arrays, variable length
arrays, unions, structures, defined types etc.

--
J C Lawrence                               Internet: claw at kanga.nu
----------(*)                             Internet: coder at kanga.nu
...Honourary Member of Clan McFud -- Teamer's Avenging Monolith...




More information about the mud-dev-archive mailing list