Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Floating Point

Functions

posh_u32_t POSH_LittleFloatBits (float f)
 
posh_u32_t POSH_BigFloatBits (float f)
 
void POSH_DoubleBits (double d, posh_byte_t dst[8])
 
double POSH_DoubleFromBits (const posh_byte_t src[8])
 
float POSH_FloatFromLittleBits (posh_u32_t bits)
 
float POSH_FloatFromBigBits (posh_u32_t bits)
 
floatPOSH_WriteFloatToLittle (void *dst, float f)
 
floatPOSH_WriteFloatToBig (void *dst, float f)
 
float POSH_ReadFloatFromLittle (const void *src)
 
float POSH_ReadFloatFromBig (const void *src)
 
double * POSH_WriteDoubleToLittle (void *dst, double d)
 
double * POSH_WriteDoubleToBig (void *dst, double d)
 
double POSH_ReadDoubleFromLittle (const void *src)
 
double POSH_ReadDoubleFromBig (const void *src)
 

Detailed Description

Unavailable if @ref POSH_NO_FLOAT "POSH_NO_FLOAT" is defined.  By
default floating point support is enabled, but if you find that
this causes problems or is inconvenient and you're not using
the support, you can define <code><b>POSH_NO_FLOAT</code></b> to disable
POSH's use of any floating point types or operations.

Here are some code examples:
*
*  //read a little-endian float from disk
*  float LoadFloat( FILE *fp )
*  {
*  float      f;
*  posh_u32_t u32;
*
*  fread( &u32, sizeof( u32 ), 1, fp );
*
*  f = POSH_FloatFromLittleBits( u32 );
*
*  return f;
*  }
*
*  //write a little-endian float to disk
*  void WriteFloat( FILE *fp, float f )
*  {
*  posh_u32_t u32;
*
*  u32 = POSH_LittleFloatBits( f );
*
*  fwrite( &u32, sizeof( u32 ), 1, fp );
*  }
*
*  

Function Documentation

posh_u32_t POSH_BigFloatBits ( float  f)

Extracts raw big-endian bits from a 32-bit floating point value

Parameters
f[in]floating point value
Returns
a big-endian bit representation of f

Definition at line 671 of file posh.cpp.

References POSH_SwapU32().

Referenced by NetBuffer::addFloat(), and s_testFloatingPoint().

672 {
673  union
674  {
675  float f32;
676  posh_u32_t u32;
677  }
678  u;
679 
680  u.f32 = f;
681 
682 #if defined POSH_LITTLE_ENDIAN
683  return POSH_SwapU32( u.u32 );
684 
685 #else
686  return u.u32;
687 #endif
688 }
void POSH_DoubleBits ( double  d,
posh_byte_t  dst[8] 
)

Extracts raw, little-endian bit representation from a 64-bit double.

Parameters
d[in]64-bit double precision value
dst[out]8-byte storage buffer
Returns
the raw bits used to represent the value 'd', in the form dst[0]=LSB

Definition at line 698 of file posh.cpp.

Referenced by NetBuffer::addDouble(), and s_testFloatingPoint().

699 {
700  union
701  {
702  double d64;
703  posh_byte_t bytes[8];
704  }
705  u;
706 
707  u.d64 = d;
708 
709 #if defined POSH_LITTLE_ENDIAN
710  dst[0] = u.bytes[0];
711  dst[1] = u.bytes[1];
712  dst[2] = u.bytes[2];
713  dst[3] = u.bytes[3];
714  dst[4] = u.bytes[4];
715  dst[5] = u.bytes[5];
716  dst[6] = u.bytes[6];
717  dst[7] = u.bytes[7];
718 #else
719  dst[0] = u.bytes[7];
720  dst[1] = u.bytes[6];
721  dst[2] = u.bytes[5];
722  dst[3] = u.bytes[4];
723  dst[4] = u.bytes[3];
724  dst[5] = u.bytes[2];
725  dst[6] = u.bytes[1];
726  dst[7] = u.bytes[0];
727 #endif
728 }
double POSH_DoubleFromBits ( const posh_byte_t  src[8])

Creates a double-precision, 64-bit floating point value from a set if raw, little-endian bits

Parameters
src[in]little-endian byte representation of 64-bit double precision floating point value
Returns
double precision floating point representation of the raw bits
Remarks
No error checking is performed, so there are no guarantees that the result is a valid number, nor is there any check to ensure that src is non-NULL. BE CAREFUL USING THIS.

Definition at line 742 of file posh.cpp.

Referenced by NetBuffer::getDouble(), and s_testFloatingPoint().

743 {
744  union
745  {
746  double d64;
747  posh_byte_t bytes[8];
748  }
749  u;
750 
751 #if defined POSH_LITTLE_ENDIAN
752  u.bytes[0] = src[0];
753  u.bytes[1] = src[1];
754  u.bytes[2] = src[2];
755  u.bytes[3] = src[3];
756  u.bytes[4] = src[4];
757  u.bytes[5] = src[5];
758  u.bytes[6] = src[6];
759  u.bytes[7] = src[7];
760 #else
761  u.bytes[0] = src[7];
762  u.bytes[1] = src[6];
763  u.bytes[2] = src[5];
764  u.bytes[3] = src[4];
765  u.bytes[4] = src[3];
766  u.bytes[5] = src[2];
767  u.bytes[6] = src[1];
768  u.bytes[7] = src[0];
769 #endif
770 
771  return u.d64;
772 }
float POSH_FloatFromBigBits ( posh_u32_t  bits)

Creates a floating point number from big-endian bits

Parameters
bits[in]raw floating point bits in big-endian form
Returns
a floating point number based on the given bit representation
Remarks
No error checking is performed, so there are no guarantees that the result is a valid number. BE CAREFUL USING THIS.

Definition at line 809 of file posh.cpp.

References bits, and POSH_SwapU32().

Referenced by NetBuffer::getFloat(), and s_testFloatingPoint().

810 {
811  union
812  {
813  float f32;
814  posh_u32_t u32;
815  }
816  u;
817 
818  u.u32 = bits;
819 #if defined POSH_LITTLE_ENDIAN
820  u.u32 = POSH_SwapU32( u.u32 );
821 #endif
822 
823  return u.f32;
824 }
float POSH_FloatFromLittleBits ( posh_u32_t  bits)

Creates a floating point number from little endian bits

Parameters
bits[in]raw floating point bits in little-endian form
Returns
a floating point number based on the given bit representation
Remarks
No error checking is performed, so there are no guarantees that the result is a valid number. BE CAREFUL USING THIS.

Definition at line 783 of file posh.cpp.

References bits, and POSH_SwapU32().

Referenced by s_testFloatingPoint().

784 {
785  union
786  {
787  float f32;
788  posh_u32_t u32;
789  }
790  u;
791 
792  u.u32 = bits;
793 #if defined POSH_BIG_ENDIAN
794  u.u32 = POSH_SwapU32( u.u32 );
795 #endif
796 
797  return u.f32;
798 }
posh_u32_t POSH_LittleFloatBits ( float  f)

Extracts raw little-endian bits from a 32-bit floating point value

Parameters
f[in]floating point value
Returns
a little-endian bit representation of f

Definition at line 645 of file posh.cpp.

References POSH_SwapU32().

Referenced by s_testFloatingPoint().

646 {
647  union
648  {
649  float f32;
650  posh_u32_t u32;
651  }
652  u;
653 
654  u.f32 = f;
655 
656 #if defined POSH_LITTLE_ENDIAN
657  return u.u32;
658 
659 #else
660  return POSH_SwapU32( u.u32 );
661 #endif
662 }
double POSH_ReadDoubleFromBig ( const void *  src)
double POSH_ReadDoubleFromLittle ( const void *  src)
float POSH_ReadFloatFromBig ( const void *  src)
float POSH_ReadFloatFromLittle ( const void *  src)
double* POSH_WriteDoubleToBig ( void *  dst,
double  d 
)
double* POSH_WriteDoubleToLittle ( void *  dst,
double  d 
)
float* POSH_WriteFloatToBig ( void *  dst,
float  f 
)
float* POSH_WriteFloatToLittle ( void *  dst,
float  f 
)