How is single precision floating point number subtraction is done?

799 Views Asked by At

Here is the example (I have converted them to decimal in advance).
A is 01000001000010000000000000000000^2 (in decimal 8.5)
B is 01000000000100000000000000000000^2 (in decimal 2.25)

The ((+A)-(+B)) should be 6.25 in decimal. Normalizing A and B and matching exponents.

A = 1.00010 * 2^3
B = 0.01001 * 2^3

I can subtract this on paper as follows.

1.00010 * 2^3
- 0.01001 * 2^3
'---------------
0.11001 * 2^3

which is 110.01^2 and in decimal is 6.25.

My problem is how does the CPU work this out? I know that CPU will convert B to twos complement and add the negative B. But every time I tried that, I got 6.75 as answer. Can someone show me how does CPU convert B to two complement to get a negative number and then add to A to get 6.25 as answer. Thanks

1

There are 1 best solutions below

0
Sanone On

I have found the answer myself. Twos complement work here as well. Convert B to a negative value using twos complement (flip bits and add 1 bit) and then add the negative to A. But the fractional part with the exponent must be calculated first. Thanks