netmsgs/libnetmsgs/nmLibPack.c
int nmPackF32(float val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
{
  static size_t fvalLen = NMFVAL_LEN_F32;     // message field value length

  union ieee754_float f;      // 4 byte floating-point number
  uint_t              uBits;  // bits

  _NM_CHK_MEM(bufSize, fvalLen);
  _NM_CHK_ARCH(val, fvalLen);

  f.f = val;

  uBits  = (uint_t)((f.ieee.negative & IEEE754_F32_SIGN_MASK)
                      << IEEE754_F32_SIGN_SHIFT);
  uBits |= (uint_t)((f.ieee.exponent & IEEE754_F32_EXPONENT_MASK)
                      << IEEE754_F32_EXPONENT_SHIFT);
  uBits |= (uint_t)((f.ieee.mantissa & IEEE754_F32_MANTISSA_MASK)
                      << IEEE754_F32_MANTISSA_SHIFT);

  switch( eEndian )
  {
    case NMEndianLittle:
      PACKLITTLE(uBits, buf);
      break;
    case NMEndianNative:
      PACKNATIVE(f.f, buf);
      break;
    case NMEndianBig:
    default:
      PACKBIG(uBits, buf);
      break;
  }

  return (int)fvalLen;
}
/*!
 * \brief Pack a 32-bit float into the message buffer.
 *
 * The IEEE 754 32-bit format is used with both the big and little endian byte
 * orders.
 *
 * \note
 *  <em>On some machines, while integers were represented in little-endian form,
 *  floating point numbers were represented in big-endian form. Because there
 *  are many floating point formats, and a lack of a standard <b>network</b>
 *  representation, no standard for transferring floating point values has been
 *  made</em> - Wikipedia.
 *
 *  \todo
 *  Detect non-IEEE 754 formats and convert to IEEE 754 prior to packing.
 *
 * \copydoc doc_params_pack_std
 * \copydoc doc_return_pack_std 
 */
\brief Pack a 32-bit float into the message buffer.
The IEEE 754 32-bit format is used with both the big and little endian byte
orders.

\note
On some machines, while integers were represented in little-endian form,
floating point numbers were represented in big-endian form. Because there
are many floating point formats, and a lack of a standard network
representation, no standard for transferring floating point values has been
made - Wikipedia.

\todo
Detect non-IEEE 754 formats and convert to IEEE 754 prior to packing.


\ brief Pack a 32 - bit float into the message buffer . The IEEE 754 32 - bit format is used with both the big and little endian byte orders . \ note On some machines while integers were represented in little - endian form floating point numbers were represented in big - endian form . Because there are many floating point formats and a lack of a standard network representation no standard for transferring floating point values has been made - Wikipedia . \ todo Detect non - IEEE 754 formats and convert to IEEE 754 prior to packing .
int nmPackF32(float val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
{
  static size_t fvalLen = NMFVAL_LEN_F32;     
  union ieee754_float f;      
  uint_t              uBits;  
  _NM_CHK_MEM(bufSize, fvalLen);
  _NM_CHK_ARCH(val, fvalLen);
  f.f = val;
  uBits  = (uint_t)((f.ieee.negative & IEEE754_F32_SIGN_MASK)
                      << IEEE754_F32_SIGN_SHIFT);
  uBits |= (uint_t)((f.ieee.exponent & IEEE754_F32_EXPONENT_MASK)
                      << IEEE754_F32_EXPONENT_SHIFT);
  uBits |= (uint_t)((f.ieee.mantissa & IEEE754_F32_MANTISSA_MASK)
                      << IEEE754_F32_MANTISSA_SHIFT);
  switch( eEndian )
  {
    case NMEndianLittle:
      PACKLITTLE(uBits, buf);
      break;
    case NMEndianNative:
      PACKNATIVE(f.f, buf);
      break;
    case NMEndianBig:
    default:
      PACKBIG(uBits, buf);
      break;
  }
  return (int)fvalLen;
}
int nmPackF32 ( float val , byte_t buf [ ] , size_t bufSize , NMEndian_T eEndian ) { static size_t fvalLen = NMFVAL_LEN_F32 ; union ieee754_float f ; uint_t uBits ; _NM_CHK_MEM ( bufSize , fvalLen ) ; _NM_CHK_ARCH ( val , fvalLen ) ; f . f = val ; uBits = ( uint_t ) ( ( f . ieee . negative & IEEE754_F32_SIGN_MASK ) << IEEE754_F32_SIGN_SHIFT ) ; uBits |= ( uint_t ) ( ( f . ieee . exponent & IEEE754_F32_EXPONENT_MASK ) << IEEE754_F32_EXPONENT_SHIFT ) ; uBits |= ( uint_t ) ( ( f . ieee . mantissa & IEEE754_F32_MANTISSA_MASK ) << IEEE754_F32_MANTISSA_SHIFT ) ; switch ( eEndian ) { case NMEndianLittle : PACKLITTLE ( uBits , buf ) ; break ; case NMEndianNative : PACKNATIVE ( f . f , buf ) ; break ; case NMEndianBig : default : PACKBIG ( uBits , buf ) ; break ; } return ( int ) fvalLen ; }
\brief Pack a 32-bit float into the message buffer.
\ brief Pack a 32 - bit float into the message buffer .
// message field value length // 4 byte floating-point number // bits