Docsity

Floating Point Arithmetic-Computer Architechture-Lecture Slides, Slides of Computer Architecture and Organization

Partial preview of the text

Download Floating Point Arithmetic-Computer Architechture-Lecture Slides and more Slides Computer Architecture and Organization in PDF only on Docsity!

Floating Point Arithmetic

Floating Point - Motivation  Review: n-bit integer representations ■ Unsigned:^

n0 to 2-

■^ Signed Two’s Complement: - 2

n-1^ n-1to 2-

■^ Biased (excess-b):

-b to 2

n-b

^ Problem: how do we represent:^ ■^ Very large numbers

9,345,524,282,135,672,^3542

■^ Very small numbers

0.00000000000000005216,-100^2

■^ Rational numbers

■^ Irrational numbers

sqrt(2)

■^ Transcendental numbers

e,^ π

Another Approach: Scientific Notation ^ Represent a number as a combination of^ ■^ Mantissa (significand): Normalized numberAND^ ■^ Exponent (base 10) ^ Example:

6.02 X 10

Significand(mantissa)

ExponentRadix(base)

Floating Point

^ Key idea: adapt scientific notation to binary^ ■^ Fixed-width binary number for significand^ ■^ Fixed-width binary number for exponent (base 2) ^ Idea: represent a number as1.xxxxxxx

yyyyX 2two Radix(2) Significand(mantissa)

Exponent

Leading ‘1’(Implicit) ^ Important Points:^ ■^ This is a tradeoff between precision and range^ ■^ Arithmetic is approximate - error is inevitable!

Floating Point Examples^3  8.75= 1 X 2+ 1 X 2ten

-1^ -2^ + 1 X 2

= 1.00011 X 2

■^ Single Precision:^ •^ Significand: 1.00011000…. (note leading 1 is implied)•^ Exponent:

two

■^ Double Precision:^ •^ Significand: 1.00011000…•^ Exponent:

two

0^ E Exponent

F Significand (^1 0 0 0 0 0) S

S^ E Exponent

F Significand F Significand^ (continued - 52 bits total) 0 1 0 0 0 0 0

Floating Point Examples

^ 8.75ten^

3 = 1 X 2

-1^ + 1 X 2

-2^ + 1 X 2

= 1.00011 X 2

3

■^ Single Precision:^ • Significand: 1.00011000…. (note leading 1 is implied)• Exponent:

3 + 127 = 130 = 10000010

two

■^ Double Precision:^ • Significand: 1.00011000…• Exponent:

3 + 1023 = 1026 = 10000000010

two

0^ E Exponent

F Significand (^1 0 0 0 0 0) S

S^ E Exponent

F Significand F Significand^ (continued - 52 bits total) 0 1 0 0 0 0 0

Floating Point Examples

^ Q: What is the value of the following single-precision word? ^ Significand =

-1^ 1 + 2

-4^ -8+ 2+ 2

-10^ + 2+ 2

^ Exponent

=^ 8 - 127 = -

^ Final Result =

-1^ (1 + 2

-4^ -8+ 2+ 2

-10^ + 2+ 2

-12-) X 2

119

= 2.36 X 10

0^ E Exponent

F Significand (^0 0 0 0 1 0) S

Special Values in IEEE Floating Point ^ 0000000 exponent - reserved for^ ■^ zero value (all bits zero)^ ■^ “Denormalized numbers” - drop the “1.”^ • Used for “very small” numbers … “gradual underflow”• Smallest denormalized number (single precision):

0.00000000000000000000001 X 2

-126 =^ -149^2

^ 1111111 exponent^ ■^ Infinity - 111111 exponent, zero significand^ ■^ NaN (Not a Number) - 1111111 exponent,nonzero significand

Floating Point Normalization  S,E,F representation allows more than onerepresentation for a particular value, e.g.^5 1.0 x 10= 0.1 x 10

6 = 10.0 x 10

4

■^ This makes comparison operations difficult ■^ Prefer to have a single representation  Hence, normalize by convention: ■^ Only one digit to the left of the floating point ■^ In binary, that digit must be a 1^ • Since leading ‘1’ is implicit, no need to store it• Hence, obtain one extra bit of precision for free

FP Overflow/Underflow

^ FP Overflow^ ■^ Analogous to integer overflow^ ■^ Result is too big to represent^ ■^ Means exponent is too big ^ FP Underflow^ ■^ Result is too small to represent^ ■^ Means exponent is too small (too negative) ^ Both can raise an exception under IEEE

FP Multiplication

^ Sign: P

= Axor Bs s^

s

^ Exponent: P

= A+ BE E^

E

■^ Due to bias/excess, must subtract bias^ e = e1 + e2E = e + 1023 = e1 + e2 + 1023E = (E1 – 1023) + (E2 – 1023) + 1023E = E1 + E2 –1023  Significand: P

= Ax BF F^

F

■^ Standard integer multiply (23b or 52b + g/r/s bits) ■^ Use Wallace tree of CSAs to sum partial products

FP Multiplication

^ Compute sign, exponent, significand ^ Normalize^ ■^ Shift left, right by 1 ^ Check for overflow, underflow ^ Round ^ Normalize again (if necessary)

Limitations on Floating-Point Math  Most numbers are approximate  Round off error is inevitable  Range (and accuracy) vary depending on exponent  “Normal” math properties not guaranteed:^ ■^ Inverse^

(1/r)*r^

≠^1

■^ Associative

(A+B) + C

≠^ A + (B+C)

(A*B) * C

≠^ A * (B*C)

■^ Distributive

(A+B) * C

≠^ AB + BC

^ Scientific calculations require error managementtake a numerical analysis for more info

IEEE Floating Point - Special Properties^ ^ Floating Point 0 same as Integer 0^ ■^ All bits = 0^ ^ Can (Almost) Use Unsigned Integer Comparison^ ■^ A > B if:^ • A.EXP > B.EXP or• A.EXP=B.EXP and A.SIG > B.SIG^ ■^ But, must first compare sign bits^ ■^ Must consider -0 == 0^ ■^ NaNs problematic^ • Will be greater than any other values• What should comparison yield?

This is equivalent tounsigned comparision!