Thread: Understanding floating point

  1. #1
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    Understanding floating point

    <background>
    I just got burned at a programming competition for not knowing the various functions related to precision/rounding floating point values. </background>
    Anyhow, i'm having trouble finding an explanation of how floating point numbers are represented in memory, and the arithmetic behind them. (Something about "mantissa" and "base"?)

    If anyone could help me out that'd be great. (Yes, I already searched google)
    Gawd, i'm such a jackass.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212

  3. #3
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198
    http://scholar.hw.ac.uk/site/computi...1.asp?outline=

    I learned about that in an architecture course last year. (mantissa sounded familiar, but I dont remember much about FPNs)

    It was under a chpater called Data Representation. I searched google for Data Representation + Floating-Point Numbers, and came up with that link.
    -MethodMan-

    Your Move:Life is a game, Play it; Life is a challenge, Meet it; Life is an opportunity, capture it.

    Homepage: http://www.freewebs.com/andy_moog/home.html

  4. #4
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    p.s. What the alphabet would look like without q and r.

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Here's a tutorial on floating point.

    http://www.nuvisionmiami.com/books/a...oating_tut.htm

    Here's some info, also about the IEEE standard on floating point.

    http://research.microsoft.com/~holla...ieeefloat.html
    http://cch.loria.fr/documentation/IEEE754/

  6. #6
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    I wrote a printf function in assembly which had to deal with floats like that (because I couldn't get the FPU code to work... )

    You have one sign bit, positive or negative. The rest are divided into the mantessa and the exponent. (Remember that bits are represented using 1 and 0.)

    Using their version of scientific notation, you come up with numbers like these:
    1.001110110 x 2^111011
    The 1 in the one's column exists for all possible numbers, so it's left out. Just the number part after the decimal point is left. The exponent is the number after "2^". (2^ is redundant also).

  7. #7
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I couldn't remember how to format floats using C++ streams, so with about 1 minute left I got a bright idea to try printf... it worked, but I didn't submit it in time. Cost me $1000 scholarship

    Anyhow, those links are perfect. Thanks everyone.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal places on Floating point number
    By manutdfan in forum C Programming
    Replies: 1
    Last Post: 10-29-2006, 12:56 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. floating point question
    By Eric Cheong in forum C Programming
    Replies: 8
    Last Post: 09-10-2004, 10:48 PM
  4. Floating point numbers in a binary file
    By frenchfry164 in forum C++ Programming
    Replies: 6
    Last Post: 07-31-2003, 10:04 AM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM