float value storage

This is a discussion on float value storage within the C Programming forums, part of the General Programming Boards category; hi, Can anyone please explain....how a float value is stored in memory. For example. The sizeof float value is 4 ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    17

    float value storage

    hi,
    Can anyone please explain....how a float value is stored in memory.

    For example.

    The sizeof float value is 4 bytes ie) 32bits.....

    If a=32.56

    The binary equivalent of 32.56 is 100000.100011111

    How this is stored in 4 bytes....

    Whether it is like this ????

    First two bytes for decimal part and next two bytes for fractinal part...

    Please explain me .....how a float value is stored in memory using 4 bytes....

    Regards,
    Rohit

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,596
    Search the Web for "IEEE 754" for the most common example.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Like laserlight alluded, there are actually several different ways of storing floating point numbers. Usually (due to the "floating" point). the number of bytes for the decimal and fractional part are not set, they vary from number to number. That's why it is often impossible to represent numbers accurately that have a huge decimal part and a large fractional part. So you can for example display a number to 20 decimal places, but once you add 10,000,000 to that, you're going to lose precision in the fractional part.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 03:25 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 04:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21