dlr::numeric::IEEEFloat32 Class Reference

The IEEEFloat32 class is for manipulating 32-bit IEEE floating point numbers. More...

#include <IEEEFloat32.h>

List of all members.

Public Types

typedef float FloatType
 This typedef specifies the native type that will be used to do computations internally.

Public Member Functions

 IEEEFloat32 ()
 Default constructor initializes to 0.0;.
 IEEEFloat32 (FloatType value)
 This constructor initializes the IEEEFloat32 instance to the value specified by its argument.
 IEEEFloat32 (unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned char byte3)
 This constructor initializes the IEEEFloat32 instance using its 32 bit binary representation.
 IEEEFloat32 (const IEEEFloat32 &source)
 This is the copy constructor.
 ~IEEEFloat32 ()
 The destructor destroys the class instance and cleans up any storage.
 operator FloatType () const
 This conversion operator returns the float as a built-in type.
unsigned char getByte (size_t index0)
 This member function returns the requested 8 bits byte from the IEEE floating point representation.
FloatType getFloat ()
 This member function returns an instance of FloatType having the same value as *this.
void setValue (FloatType value)
 This member function sets the IEEEFloat32 instance to the value specified by its argument.
void setValue (unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned char byte3)
 This member function sets the IEEEFloat32 instance using the 32 bit binary representation.


Detailed Description

The IEEEFloat32 class is for manipulating 32-bit IEEE floating point numbers.

This class is useful if, for example, you need to figure out * what specific pattern of bits represents the number 1.347 in 32 bit * IEEE floating point format, and you're not sure that your machine * uses IEEE floating point representation.

The 32-bit IEEE floating point format is one sign bit (s), followed by an 8-bit biased exponent, followed by a fraction from the normalized mantissa (f). This is broken into bytes as follows:

| seeeeeee | efffffff | ffffffff | ffffffff |

This arrangements of bits represents a real number, F, according to the following formula:

F = (-1)^s * 2E(e - 127) * (1.f)_2,

where the notation (1.f)_2 means "the 24 bit binary number consisting of 1, followed by the 23 bits of f, where the 23 bits of f represent the fractional part. That is the first bit of f has a weight of 2E-1, the second has a weight of 2E-2, and so on.

WARNING: This class currently does not handle NaN or Inf values. Furthermore, the value -0.0 is silently converted to 0.0.

Definition at line 53 of file IEEEFloat32.h.


Member Typedef Documentation

This typedef specifies the native type that will be used to do computations internally.

It must have at least as many exponent and mantissa bits as IEEE 32-bit floating point representation.

Definition at line 62 of file IEEEFloat32.h.


Constructor & Destructor Documentation

dlr::numeric::IEEEFloat32::IEEEFloat32 (  ) 

Default constructor initializes to 0.0;.

Definition at line 27 of file IEEEFloat32.cpp.

References setValue().

dlr::numeric::IEEEFloat32::IEEEFloat32 ( FloatType  value  ) 

This constructor initializes the IEEEFloat32 instance to the value specified by its argument.

Parameters:
value This argument specifies the value of the float in question.

Definition at line 39 of file IEEEFloat32.cpp.

References setValue().

dlr::numeric::IEEEFloat32::IEEEFloat32 ( unsigned char  byte0,
unsigned char  byte1,
unsigned char  byte2,
unsigned char  byte3 
)

This constructor initializes the IEEEFloat32 instance using its 32 bit binary representation.

Parameters:
byte0 This argument represents the first 8 bits of the binary representation (the sign bit and the first 7 exponent bits).
byte1 This argument represents the second 8 bits of the binary representation (the final exponent bit and the first 7 mantissa bits).
byte2 This argument represents the third 8 bits of the binary representation (the 8th - 15th mantissa bits).
byte3 This argument represents the final 8 bits of the binary representation (the 16th - 23rd mantissa bits).

Definition at line 51 of file IEEEFloat32.cpp.

References setValue().

dlr::numeric::IEEEFloat32::IEEEFloat32 ( const IEEEFloat32 source  ) 

This is the copy constructor.

It deep copies its argument.

Parameters:
source This argument is the IEEEFloat32 instance to be copied.

Definition at line 65 of file IEEEFloat32.cpp.

References m_bytes.

dlr::numeric::IEEEFloat32::~IEEEFloat32 (  )  [inline]

The destructor destroys the class instance and cleans up any storage.

Definition at line 118 of file IEEEFloat32.h.


Member Function Documentation

unsigned char dlr::numeric::IEEEFloat32::getByte ( size_t  index0  ) 

This member function returns the requested 8 bits byte from the IEEE floating point representation.

Parameters:
index0 This argument specifies which byte to return. If its value is zero, the sign bit and 1st 7 exponent bits will be returned. If its value is one, the final exponent bit and the first 7 mantissa bits will be returned. If its value is two, the subsequent 8 mantissa bits will be returned. If its value is two, the final 8 mantissa bits will be returned.
Returns:
The return is an unsigned char containing the requested 8 bits of the IEEE floating point representation.

Definition at line 77 of file IEEEFloat32.cpp.

FloatType dlr::numeric::IEEEFloat32::getFloat (  )  [inline]

This member function returns an instance of FloatType having the same value as *this.

It is provided for those times when an implicit type conversion isn't possible, and a static_cast is too clunky.

Returns:
The return value is a FloatType instance having the value represented by *this.

Definition at line 159 of file IEEEFloat32.h.

dlr::numeric::IEEEFloat32::operator FloatType (  )  const [inline]

This conversion operator returns the float as a built-in type.

Returns:
The return value is a FloatType instance corresponding to the number described by this class.

Definition at line 128 of file IEEEFloat32.h.

void dlr::numeric::IEEEFloat32::setValue ( unsigned char  byte0,
unsigned char  byte1,
unsigned char  byte2,
unsigned char  byte3 
)

This member function sets the IEEEFloat32 instance using the 32 bit binary representation.

Parameters:
byte0 This argument represents the first 8 bits of the binary representation (the sign bit and the first 7 exponent bits).
byte1 This argument represents the second 8 bits of the binary representation (the final exponent bit and the first 7 mantissa bits).
byte2 This argument represents the third 8 bits of the binary representation (the 8th - 15th mantissa bits).
byte3 This argument represents the final 8 bits of the binary representation (the 16th - 23rd mantissa bits).

Definition at line 118 of file IEEEFloat32.cpp.

void dlr::numeric::IEEEFloat32::setValue ( FloatType  value  ) 

This member function sets the IEEEFloat32 instance to the value specified by its argument.

Parameters:
value This argument specifies the value of the float in question.

Definition at line 94 of file IEEEFloat32.cpp.

Referenced by IEEEFloat32().


The documentation for this class was generated from the following files:

Generated on Wed Nov 25 00:42:49 2009 for dlrUtilities Utility Library by  doxygen 1.5.8