Page 1 of 1

Floating point representation

Posted: Wed Oct 12, 2011 11:58 pm
by Kyosaur
I've been reading a TON regarding this topic, yet im still very confused on the matter. How are floating point numbers represented? Everything i've read has basically told me the same exact thing, and has never showed an example that i was able to understand! I feel as though i've read so much differently stated information, that nothing make sense/is correct anymore. This my current understanding, please correct what isnt right.

The MSB (2^31 for 32bit system) is responsible for the negative/positive sign like it is with normal signed integers. The next 8 bits are a biased exponent (this is what i understand to be val - 127? With a range of 1-254 (0/255 are for special numbers)). The remaining bits, the mantissa/significand, are for the fraction data.

The thing that im seriously having problems with is CONVERTING. Im trying to make sense of a floating number, but i just get data that doesnt remotely make sense to me. These are my issues with converting (i know some of the stuff is going to sound stupid- i dont mind appearing stupid as long as i learn):
  • Converting FROM float:
    • Code: Select all

      Original number: 13.37
      Binary number: 01000001010101011110101110000101
      
      MSB: 0.
      Biased Exponent: 130 (10000010).
      Mantissa: 5630853 (10101011110101110000101).
      
      Mantissa * 10^130 will never equal our desired value "13.37" no matter where we put the decimal (or radix point). This is seriously confusing!
    Converting TO float:
    • My main issue with converting TO a float value comes from lack of information + sleep deprivation. The first bit of information is where does the decimal point start? I've seen scientific notation denoted tons of different ways, so which one is correct here? If i store 1337 inside of the mantissa where does the decimal go? (Is it safe to assume it goes 1.337? I've seen it go 0.1337). Its important to know where the decimal goes, other wise it could be off when multiplying :'(.
    • The biased exponent is confusing. Assuming the exponent is implicitly placed after the one (1.337) i want to multiply it by 10^1. This is normally would be straight forward, except we have the bias to account for, which makes me unsure HOW i should store the value 1. Do i store it as 0b1 (0b1 - 127 = -126) or do i store it as 0b10000000 (128 - 127 = 1). I might be over thinking this part. I believe it to be the first, but it feels so unnatural and confusing (especially when READING).
Can someone tell me what i am doing wrong, and answer the questions above? I know this is an advanced subject, but its bothering me that i cant make sense of floating point numbers (especially since i have a good understanding of binary!).

Re: Floating point representation

Posted: Thu Oct 13, 2011 12:57 pm
by szdarkhack
Here is a wikipedia link of the conversion process, both FROM and TO float (single precision/32bits):
http://en.wikipedia.org/wiki/Single_pre ... y32_format

My guesses as to what might be giving you wrong results are the following:
-Are you normalizing the numbers correctly? That means that there must be ONE digit on the left of the decimal point, no more than that.
-Did you remember to account for the implied bit 24?
-Do you convert the fractional part of the number to binary correctly?

Any of these could be the causes, but check out the link, it gives examples both ways. I hope that will clear this up for you :)

Re: Floating point representation

Posted: Fri Oct 14, 2011 10:10 pm
by Kyosaur
Thanks for the link, but im still very confused xD. Im just gonna keep doing some digging until i get it. If anyone actually understands what im doing wrong, or even the process itself, please try to explain it to me :( lol. To be completely honest im just tired of reading about this subject- its exhausting! Curse my need to know how stuff works :evil:.

Re: Floating point representation

Posted: Sat Oct 15, 2011 2:21 am
by short
Kyosaur wrote:To be completely honest im just tired of reading about this subject-.
Take a break from it for a week. Do something productive, such as...... watching the entirety of Battlestar Galactica season 1-4, then come back too it. :lol:

Seriously, sometimes a little break helps. When you come back it will be easier to digest, as it will be the second time and your brain will be more familiar with it (and you won't be burnt out).

Re: Floating point representation

Posted: Sat Oct 15, 2011 11:40 pm
by qpHalcy0n
...or take a shit.

Shits help the thought process. Not really kidding....