Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Munich, Germany
    Thanked 13 Times in 13 Posts

    I have a question of how floating point numbers work

    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;
    		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?

    Last edited by BrickInTheWall; 06-27-2009 at 05:54 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts