Lecture06 - 0306-381 Applied Programming • Floating-Point...

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 • Floating-Point Multiplication • Exam One 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 Multiplication Two floating-point numbers • A = (-1)SA ´ 2EA - Bias ´ 1.FA • B = (-1)SB ´ 2EB - Bias ´ 1.FB Product • C =A ´ B = (-1)SC ´ 2EC - Bias ´ 1.FC A ´ B = [- 1]S A ´ 2 E A - Bias ´1.F A ´ [- 1]SB ´ 2 EB - Bias ´1.F B = (- 1)S A ´ (- 1)S B ´ 2 E A - Bias ´ 2 EB - Bias ´ 1.F A´1.F B = (- 1)S A + S B ´ 2 E A - Bias+ EB - Bias ´1.F A´1.F B 4 ( )( ) Floating-Point Multiplication Algorithm: Sign A ´ B = (- 1)S A + S B ´ 2 E A - Bias + EB - Bias ´ 1.F A´1.F B C = (- 1) SC ´ 2 EC - Bias ´1.F C • Look at signs of factors (muliplicand and multiplier) – Same signs ® Positive result – Different signs ® Negative result • S field outcome: (SA, SB) ® SC – Same signs ® Positive result (0,0) ® 0 (0,1) ® 1 or or (1,1) ® 0 (1,0) ® 1 – Different signs ® Negative result Integer operation on SA and SB: SC ¬ SA Å SB C bit-wise XOR: SC = SA ^ SB ; 5 Floating-Point Multiplication Algorithm: Exponent (perhaps not final value) A ´ B = (- 1)S A + S B ´ 2 E A - Bias + EB - Bias ´ 1.F A´1.F B C = (- 1)SC ´ 2 EC - Bias ´1.F C Add exponents and adjust for bias • EC - Bias = EA - Bias + EB – Bias EC = EA + EB – 2Bias + Bias = EA + EB – Bias Exponent may need adjustment later. Why? 6 Floating-Point Multiplication Algorithm Significand A ´ B = (- 1)S A + S B ´ 2 E A - Bias + EB - Bias ´ 1.F A´1.F B C = (- 1) SC ´ 2 EC - Bias ´1.F C • Multiply significands (not just fractional parts) • Truncate fraction bits not available in format • Normalize significand result, if necessary – If most significant “1” digit is not in “one” position • Shift significand bits to get first significant “1” in “one” position • Adjust result exponent (EC) to account for shifting • FC is fractional part of normalized significand 7 Floating-Point Multiplication Example IEEE-754 Single Precision Multiply 2048.12510 by -0.7510 S E 100000000000.001 x -.11 ----------------1000000000.00001 -10000000000.0001 -------------------11000000000.00011 2048.125 x -.75 ---------102.40625 -1433.6875 -----------1536.09375 F 0 10001010 00000000000001000000000 1 01111110 10000000000000000000000 • Sign Negative: 0 Å 1 = 1 • Exponent 137 = 138 + 126 – 127 • Fraction 1.00000000000001000000000 x1.10000000000000000000000 -------------------------- .100000000000001000000000 +1.00000000000001000000000 -------------------------1.1000000000000110000000000000000000000000000000 S=1; E=10001001; F=10000000000001100000000 8 ...
View Full Document

Ask a homework question - tutors are online