lecture33 - 0306-381 Applied Programming Lecture...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-381 Applied Programming Lecture Thirty-Three • Floating-Point Addition Floating-Point Nomenclature Decimal Scientific Notation X = a ´ 10b – a: Significand or mantissa – b: Exponent • Binary Scientific Notation X = a ´ 2b – a: Binary significand or mantissa – b: Binary exponent Basis of binary floating-point representations 2 IEEE-754 Floating Point Format Normalized Value = (-1)S ´ 2E - Bias ´ 1.F • S: sign • E: biased exponent • F: fractional part of significand Special case: zero value—detection • Only normalized allowed E = 0 for normalized values • Denormalized allowed E = 0 and F = 0 3 Floating-Point Addition: Operands Two floating-point numbers • A = (-1)SA ´ 2EA - Bias ´ 1.FA • B = (-1)SB ´ 2EB - Bias ´ 1.FB Sum • C =A + B = (-1)SC ´ 2EC - Bias ´ 1.FC 4 Floating-Point Addition ( = ( [- 1] A + B = [- 1] ´ 2 SA SA E A - Bias ) ( )+ ´1.F A + [- 1] ´ 2 EB - Bias ´1.F B ´ 2 E A - Bias ´1.F A SB ) æ ö 2 E A - Bias SB E B - Bias ç [- 1] ´ E - Bias ´ 2 ´ 1.F B ÷ ç ÷ 2 A è ø = ( [(- 1) SA ) ´ 1.F A ´ 2 E A - Bias + æ é 2 EB - Bias ù E A - Bias ö ç ê(- 1)S B ´ 1.FB ´ E - Bias ú ´ 2 ÷ ç ÷ 2 A û è ë ø ( [(- 1) ´1.F ]´ 2 )+ ( [(- 1) ´1.F ´ 2 ]´ 2 ) = ( [ (- 1) ´1.F ]+ [ (- 1) ´ 1.F ´ 2 = SA A SB B SA E A - Bias EB - E A E A - Bias SB A B EB - E A )´ 2 E A - Bias 5 Floating-Point Addition Algorithm: Sign ( ) A + B = [(-1) S A ´1.F A] + [(-1) S B ´1.FB ´ 2 EB - E A ] ´ 2 E A - Bias C = (- 1) ´ 2 SC EC - Bias ´1.F C If EA > EB • A and B have same sign (SA == SB) C has that same sign (SC = SA; SC = SB) • A and B have different signs (SA != SB) C has sign of A or B with maximum magnitude (SC = SMAX(A,B)) • A and B have different exponents (EA != EB) C has sign of number with largest exponent (SC = SMAX(EA,EB)) • A and B have same exponent (EA == EB) C has sign of number with largest significand (SC = SMAX(FA,FB)) 6 Floating-Point Addition Algorithm: Exponent (perhaps not final value) ( ) A + B = [(-1) S A ´1.F A] + [(-1) S B ´1.FB ´ 2 EB - E A ] ´ 2 E A - Bias C = (- 1)SC ´ 2 EC - Bias ´1.F C If EA > EB Choose largest exponent (augend or addend) • EC = Maximum of EA and EB Exponent may need adjustment later. Why? 7 Floating-Point Addition Algorithm: Significand Alignment ( ) A + B = [(-1) S A ´1.F A] + [(-1) S B ´1.FB ´ 2 EB - E A ] ´ 2 E A - Bias C = (- 1)SC ´ 2 EC - Bias ´1.F C If EA > EB • Align binary point of smaller number to larger number – Shift smaller number right |EB-EA| bits – Maximum exponent now applies to both numbers • Significand outcome – Maximum of A and B unchanged – Minimum of A and B aligned to maximum • Minimum = Minimum ´ 2-|EB-EA| • Minimum = Minimum >> |EB-EA| 8 Floating-Point Addition Algorithm: Aligned Significand Addition ( ) A + B = [(-1) S A ´1.F A] + [(-1) S B ´1.FB ´ 2 EB - E A ] ´ 2 E A - Bias C = (- 1)SC ´ 2 EC - Bias ´1.F C If EA > EB “One” position • Add significands (not just fractional parts) – Both of same sign: add – Different signs: subtract smaller from larger • Normalize significand result, if necessary If most significant “1” digit is not in “one’s” position • Shift significand bits to get first significant “1” in “one’s” position • Adjust result exponent (EC) to account for shifting • FC is fractional part of normalized significand 9 Floating-Point Addition Algorithm: Check Result ( ) A + B = [(-1) S A ´1.F A] + [(-1) S B ´1.FB ´ 2 EB - E A ] ´ 2 E A - Bias C = (- 1)SC ´ 2 EC - Bias ´1.F C If EA > EB • Check for zero (C == 0) – Significand is zero – Set exponent to zero (EC = 0) • Overflow Exponent greater than 127 (EC > 254) • Underflow Exponent less than -126 (EC < 1) 10 Floating-Point Addition Example IEEE-754 Single Precision Add 5.010 and 2.510 S 101.0 + 10.1 ----------------111.1 E F 0 10000001 01000000000000000000000 0 10000000 01000000000000000000000 • Sign Positive: (EA > EB) Þ SC ¬ SA • Exponent (for addition) 129: (EA > EB) Þ EC ¬ EA • Fraction 5.0 +2.5 --------7.5 1.01000000000000000000000 Significand alignment +0.10100000000000000000000 -------------------------1.11100000000000000000000 Normalization 1.11100000000000000000000 S=0; E=10000001; F=11100000000000000000000 11 Floating-Point Addition Example IEEE-754 Single Precision Add 2048.12510 and -.7510 S 100000000000.001 + -.11 ----------------11111111111.011 E F 0 10001010 00000000000001000000000 1 01111110 10000000000000000000000 • Sign Positive: (EA > EB) Þ SC ¬ SA • Exponent (for addition) 138: (EA > EB) Þ EC ¬ EA • Fraction 2048.125 -.75 --------2047.375 1.00000000000001000000000 Significand alignment -0.00000000000110000000000 -------------------------0.11111111111011000000000 Normalization 1.11111111110110000000000 S=0; E=10001001; F=11111111110110000000000 12 ...
View Full Document

Ask a homework question - tutors are online