Question:
Understanding Floating Point Addition Using Computer Arithmetic?
bdaustrin
2013-05-13 14:45:42 UTC
Can anyone explain how to do floating point addition with computer arithmetic? I'm having a hard time understanding how this is done.

If I'm given something like:
1 1011 101101 + 0 1100 011010

How do I add those together?
Three answers:
husoski
2013-05-13 16:11:42 UTC
You didn't specify what the format was, so I'm going to guess that the bits are:



s xxxx ffffff

s = sign bit (0=+, 1=-)

xxxx = exponent plus 8 (1000 binary)

ffffff = fraction bits to follow an implied leading "1."



The first thing to do is to align the binary points. By hand, I do that by representing both numbers in the binary version of standard form. The above format makes the first number equal to

-1.101101 x 2^3 = -1101.101 .... sign-1 exponent = 8+3, fraction =x.101101



The second number is:

+1.011010 x 2^4 = +10110.10



Adding opposite signs means subtracting the smaller magnitude from the larger magnitude and keeping the sign from the number with the larger magnitude. The positive number is larger, to the result sign bit will be 0 and the numeric value can be calculated by binary subtraction:



. 10110.10

..- 1101.101

----------------

.= 1000.111



The leading dots are an attempt to line things up. That result is converted back to floating point the new value in binary "scientific" form is 1.000111 x 2^3, which is:

0 1011 000111



...in my guess at your format.
Robert J
2013-05-13 14:59:36 UTC
To start with, you need to know *what* floating point format the numbers are in - which sets of bits are exponent, mantissa, implied bit, the sign bits and any exponent bias (offset).



FP formats generally use a multiple of eight bits (eg. 16, 24, 32 or 64 in total), I've never seen one that uses eleven bits.





Once you know the format, you initially check if there is any overlap in the mantissas - if the exponents differ by more than the number of bits in the mantissa, the smaller of the two numbers is not big enough to change the value of the larger.



If they overlap, add them with appropriate alignment offsets.



If the result overflows, shift it and adjust the result exponent.



See the link below for more details of floating point representations.



Edit - second link added, to the source code download for a software floating-point math library package.

If you unzip it and look in the file softfloat.c, you can look at the addition routine starting at line 707







A bit more info about binary floating point formats, if you are not familiar with them.. It can take a while to get your head around the concepts if you have only worked with binary integers.



With binary fractions, the digits to the right of the 'decimal point' (or strictly, binary point) halve in value with each digit; 0.1 is a half, 0.001 one eighth etc.





Think of a binary FP number as a bit like a decimal in Scientific notation or Standard form.

Rather than a simple number with a decimal (binary) point, the number is shifted to 'normalise' it with the most significant digit in a fixed place. That's the mantissa, the amount of shift places used is the exponent.



The exponent is normally offset by half it's range to avoid 'no shift' being stored as zero, and an actual zero in the exponent part signifies the stored number is zero.

eg. with an eight bit exponent, a zero shift is stored as 128.



For any non-zero binary number, the most significant digit will be a 1...



As you know there is a 1 in a fixed place after normalisation, that can be omitted for storage to give a another significant digit, then put back when the number is unpacked to do any operations on it.
?
2016-12-24 17:35:38 UTC
RE: I see issues in my eyes (black issues floating) specifically as quickly as I awaken or whilst im utilising the computer.? as quickly as I awaken or am utilising the computer or whilst i glance with greater interest I see small issues floating in my eyes. it somewhat is terrible specifically whilst im attempting to verify some thing on my computer or whilst im interpreting. I don't wanna circulate to the surgeon if this occurs to anybody. Do you spot small...


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...