- Asked 6/22
- 2078 Kartik · 6 marks
- 2078 Bhadra · 3+3 marks
- 2074 Chaitra · 10 marks
- 2073 Shrawan · 6 marks
- 2070 Asar · 4 marks
- 2069 Asar · 6 marks
Floating point addition and subtraction
Short answer
To add/subtract, align exponents by shifting the smaller mantissa right. Then add/subtract mantissas, normalize (shift left on leading zero, shift right on overflow). Example: 1.101×2³ + 0.011×2³ = 10.000×2³ → 1.000×2⁴ = 16.
Explain the floating point addition and subtraction algorithm with flowchart and example.
A floating-point number is X = m × 2^e (mantissa m, exponent e; the exponent is biased in IEEE 754). To add or subtract two such numbers, their exponents must first be made equal.
Algorithm (steps)
- Check for zeros: if either operand is 0, the result is the other operand (for subtraction, with its sign changed if it is the subtrahend).
- Align the mantissas: compare the exponents. Shift the mantissa of the number with the smaller exponent right by the difference, increasing its exponent with each shift, until the exponents are equal.
- Add or subtract the mantissas (for subtraction, change the sign of the second operand and add) using the signed-mantissa rules. The result gets the common exponent.
- Check for a zero result and for mantissa overflow: if the mantissa overflows (carry out), shift it right by one and increase the exponent by 1.
- Normalise the result: if the mantissa has leading zeros, shift it left and decrease the exponent for each shift, until the first digit is non-zero (1.xxx in binary).
- Check for exponent overflow or underflow, round the mantissa if needed, and give the result.
Start
|
Is X or Y zero? --yes--> result = other operand
| no
Align mantissas (shift smaller right)
|
Add / subtract mantissas
|
Result zero? --yes--> result = 0
| no
Mantissa overflow? --yes--> shift right, e = e + 1
| no
Normalise (shift left, e = e - 1)
|
Exponent overflow/underflow? --yes--> report error
| no
Stop
Example 1 (addition): 13 + 3
X = 1.101 × 2³ (13), Y = 1.100 × 2¹ (3).
- Exponent difference = 3 - 1 = 2; shift Y right 2 places: 0.011 × 2³.
- Add: 1.101 + 0.011 = 10.000 (carry out).
- Overflow: shift right 1 and increment the exponent: 1.000 × 2⁴.
- Result = 1.000 × 2⁴ = 16 ✓
Example 2 (subtraction): 13 - 3
- Align as above: Y = 0.011 × 2³.
- Subtract: 1.101 - 0.011 = 1.010.
- Already normalised: 1.010 × 2³ = 1.25 × 8 = 10 ✓
(If the result has leading zeros, for example 1.101 - 1.100 = 0.001, shift it left 3 times and decrease the exponent by 3.)
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Floating point division algorithm · Computer Organization and Architecture, chapter 5 · asked 4×
- Floating point multiplication · Computer Organization and Architecture, chapter 5 · asked 3×
- Non-restoring division with flowchart · Computer Organization and Architecture, chapter 5 · asked 3×
- Algorithm and flowchart for largest · Computer Programming, chapter 2
- Algorithm and flowchart: quadratic roots · Computer Programming, chapter 2
- Algorithm and flowchart: distance between points · Computer Programming, chapter 2
- Algorithm and flowchart help; Armstrong flowchart · Computer Programming, chapter 2
All Computer Organization and Architecture chapter 5 questions →