Yeah.
WARNING: LONG POST AHEAD.Spec: you can correct me if any of this is a bit off.
Floating point numbers (numbers with a decimal and such, like 3.1415926535) are the most difficult types of numbers to represent and work with in computers. Because they are a complex number, an operation with them is a lot slower and more cumbersome than an operation on a normal number. If you were adding 10 and 5 together (1010 and 0101 respectively) you'd get 16 (1111). I won't go into much more detail, other than to say that adding the 2 simple binary numbers is really easy to do. However, floating point numbers are much more complicated.
The IEEE-754 standard defines a floating point number like this:
It's 32 bits long.
It's made up of 3 sections.
It's basically like this: +/- mantissa * 2 ^ exponent. (that is: positive or negative identifier, mantissa times 2 to the power of exponent)
The Sign Bit: A single binary bit telling whether the number is positive or negative.
The Exponent: The exponent can range from -127 to +128. It doesn't have a sign bit. Since there are 256 possible numbers, to get that range to go from -127 to +128, we simply subtract 127 from whatever number is stored here. 2 is raised to this power and the mantissa is multiplied with it to get the real number we're representing with this.
The Mantissa: The mantissa is the bulk of the actual number. It's 23 bits long when stored. This number always has a 1 in front of it so it totals as 24 bits in reality.
Here's an example: we want to represent the number -12.5.
The binary representation is:
SEEEEEEE | EMMMMMMM | MMMMMMMM | MMMMMMMM |
11000001 | 01001000 | 00000000 | 00000000 |
- S being the Sign Bit.
- E the exponent.
- And M being the mantissa.
Now, let's take the number apart:
- The Sign Bit is 1. That means it's negative.
- The exponent value is 10000010 binary or 130 decimal. Subtracting 127 from 130 leaves 3, which is the actual exponent. (remember, this means 2 to the power of 3)
- The mantissa appears as the following binary number:
1001000 00000000 00000000 - This number always has a 1 added onto the left end of it, making it 24 bits, instead of 23, and gives this value:
1.1001000 00000000 00000000 - Now we need to adjust the mantissa, according to the exponent. We move the point left for negative numbers, and right for positive. The result is this:
1100.1000 00000000 00000000 - Everything to the left of the decimal represents a binary number by itself. 1100 is the number 12 (23 + 22, which is 8 + 4).
- Everything to the right of it also represents another binary number. However, this one is a bit different. Instead of representing the positive powers of 2, this part represents negative powers of 2. For example, .1000 represents 1 x 2-1 + 0 x 2-2 + 0 x 2-3 + 0 x 2-4. 2-1 = .5.
- If you add the 12 and the .5 sections together, and use the sign bit to realize it,s a negative number, you realize that we now have the number -12.5.
Now, if we were to add numbers like that, it'd be a pretty complex process, taking a lot longer than even simple addition.
You first make the numbers have the same exponent (in a computer, even this takes a couple steps), then add the 2 mantissas together, and then round off to the requisite number of digits (I think this would also have a number of steps to it).