Another floating point question

This is a discussion on Another floating point question within the C Programming forums, part of the General Programming Boards category; The question asks, what is the largest unsigned int that can be represented between two floats? and what does it ...

  1. #1
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73

    Another floating point question

    The question asks, what is the largest unsigned int that can be represented between two floats? and what does it round to?

    The answer is that it falls between 2^(32) and 2^(32)-2^(8) and half way between those two floats is 2^(32)-2^(7) which rounds to 2^32 away from odd..

    What i dont get is, where did they get 2^8 from???

    can anyone help?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    In a standard thirty-two bit float, you've only got 23 bits (plus an implicit one) of mantissa; so if you have an integer with two 1's twenty-four spots apart, then you can't represent it in a float.

  3. #3
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73
    so if i represent the largest unsigned int which is 2^32 we have in the exponent 2^159 which can still represent 2^32 right? 159-32 = 127 which is the bias. so where are we adding the extra 1? i know it falls off the right end -- but how did they choose 2^8??

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Think for a minute: 1000 0000 0000 0000 0000 0000 1111 1111. Try to fit that into the mantissa of a floating point number.

  5. #5
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73
    sign or unsigned?

  6. #6
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73
    if u fit that in the mantissa it would over flow right? the bits on the right will fall to the guard bits

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by NoobieGecko View Post
    if u fit that in the mantissa it would over flow right? the bits on the right will fall to the guard bits
    What guard bits? What are you even talking about?

    Remember how to put numbers into floating-point?
    1. Write the number in binary notation
    2. Put it into "binary scientific" form
    3. Take the "1." in front and make it implicit
    4. Put the exponent, plus 127, into the exponent field
    5. Put the number behind the binary point, or the first 23 digits of it correctly rounded, into the mantissa

    Now, do that for the number 4,294,967,551. Show your work, and you'll see what is going on.

  8. #8
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73
    i'm slow, i can't do that in 15 mins tabs, plus i got a midterm in 13 minutes =(
    how about i do that after the midterm? i'll figure it out, thanks alot!!

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    Quote Originally Posted by NoobieGecko View Post
    i'm slow, i can't do that in 15 mins tabs, plus i got a midterm in 13 minutes =(
    how about i do that after the midterm? i'll figure it out, thanks alot!!
    You're lucky you even got a response in under 1 hour. This is not the place for last minute cramming.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    [QUOTE=NoobieGecko;727871]i'm slow, i can't do that in 15 mins tabs, plus i got a midterm in 13 minutes =(
    how about i do that after the midterm? i'll figure it out, thanks alot!![/QUOTE

    You go to Berkeley and you don't have a calculator that converts to binary? Shame.

    Also, I can't use my calculator, so try the number 4,294,967,041 instead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  2. Floating point #'s, why so much talk about it?
    By scuzzo84 in forum C Programming
    Replies: 5
    Last Post: 09-20-2005, 04:29 PM
  3. floating point operators
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2003, 07:53 PM
  4. floating point exception? what causes these?
    By salvelinus in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2002, 12:12 PM
  5. Floating point numbers
    By bulsquare in forum C Programming
    Replies: 2
    Last Post: 04-10-2002, 04:44 AM

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