BrickInTheWall

06-27-2009, 04:38 PM

Hello everybody...I want to know how floating point numbers are stored and calculated. I would like to start my question using a double precision floating point variable...I'm using this C++ code to look at its structure:

typedef union

{

double fp;

struct

{

unsigned long lo;

unsigned long hi;

};

} hack_structure;

using namespace std;

// Create hack_structure

hack_structure x;

If I for example set x.fp to 300 and look at x.hi and x.hi I'll get:

x.hi = 1081262080

x.lo = 0

Can anyone explain to me how these are built up (probably easiest to explain in binary)...As far as I know, the MSB is the sign bit, the next 10 highest bits go towards the exponent of the number, and the rest are for the mantissa...I've been reading some stuff about floating point numbers but a lot of it just raises more questions for me...If I look at x.hi then I just have to look at the 10 highest bits AFTER the MSB to get the exponent right? Also, how is the mantissa calculated...shouldn't it be normalized?

edit: oh and what is the standard exponent bias?

Cheers,

Chris

typedef union

{

double fp;

struct

{

unsigned long lo;

unsigned long hi;

};

} hack_structure;

using namespace std;

// Create hack_structure

hack_structure x;

If I for example set x.fp to 300 and look at x.hi and x.hi I'll get:

x.hi = 1081262080

x.lo = 0

Can anyone explain to me how these are built up (probably easiest to explain in binary)...As far as I know, the MSB is the sign bit, the next 10 highest bits go towards the exponent of the number, and the rest are for the mantissa...I've been reading some stuff about floating point numbers but a lot of it just raises more questions for me...If I look at x.hi then I just have to look at the 10 highest bits AFTER the MSB to get the exponent right? Also, how is the mantissa calculated...shouldn't it be normalized?

edit: oh and what is the standard exponent bias?

Cheers,

Chris