Docsity

Introduction To Computer System Floating Points, Lecture Slide - Computer Science, Slides of Computer System Design and Architecture

Partial preview of the text

Download Introduction To Computer System Floating Points, Lecture Slide - Computer Science and more Slides Computer System Design and Architecture in PDF only on Docsity!

Instructors: Randy Bryant & Dave O’Hallaron

Floa.ng Point

15-­‐213: Introduc<on to Computer Systems 3 rd^ Lecture, Aug. 31, 2010

Today: Floa.ng Point

 Background: Frac<onal binary numbers

 IEEE floa<ng point standard: Defini<on

 Example and proper<es

 Rounding, addi<on, mul<plica<on

 Floa<ng point in C

 Summary

2 i 2 i-­‐ 4 2 1 1/ 1/ 1/ 2 -­‐j

bi bi-­‐1 ••• b 2 b 1 b 0 b-­‐1 b-­‐2 b-­‐3 ••• b-­‐j

  • • •

Frac.onal Binary Numbers

 Representa<on

 Bits to right of “binary point” represent frac<onal powers of 2

 Represents ra<onal number:

  • • •

Frac.onal Binary Numbers: Examples

 Value Representa<on

 Observa<ons

 Divide by 2 by shi]ing right

 Mul<ply by 2 by shi]ing le]

 Numbers of form 0.111111… 2 are just below 1.

i

  • … ➙ 1.  Use nota<on 1.0 – ε

Today: Floa.ng Point

 Background: Frac<onal binary numbers

 IEEE floa<ng point standard: Defini<on

 Example and proper<es

 Rounding, addi<on, mul<plica<on

 Floa<ng point in C

 Summary

IEEE Floa.ng Point

 IEEE Standard 754

 Established in 1985 as uniform standard for floa<ng point arithme<c

 Before that, many idiosyncra<c formats

 Supported by all major CPUs

 Driven by numerical concerns

 Nice standards for rounding, overflow, underflow

 Hard to make fast in hardware

 Numerical analysts predominated over hardware designers in defining standard

Precisions

 Single precision: 32 bits

 Double precision: 64 bits

 Extended precision: 80 bits (Intel only)

s exp frac 1 8-bits 23-bits s exp frac 1 11-bits 52-bits s exp frac 1 15-bits 63 or 64-bits

Normalized Values

 Condi<on: exp ≠ 000…0 and exp ≠ 111…

 Exponent coded as biased value: E = Exp – Bias

 Exp: unsigned value exp

 Bias = 2

k-­‐ -­‐ 1, where k is number of exponent bits  Single precision: 127 (Exp: 1…254, E: -­‐126…127)  Double precision: 1023 (Exp: 1…2046, E: -­‐1022…1023)

 Significand coded with implied leading 1: M = 1.xxx…x 2

 xxx…x: bits of frac

 Minimum when 000…0 (M = 1.0)

 Maximum when 111…1 (M = 2.0 – ε)

 Get extra leading bit for “free”

Denormalized Values

 Condi<on: exp = 000…

 Exponent value: E = –Bias + 1 (instead of E = 0 – Bias)

 Significand coded with implied leading 0: M = 0.xxx…x 2

 xxx…x: bits of frac

 Cases

 exp = 000…0, frac = 000…

 Represents zero value  Note dis<nct values: +0 and –0 (why?)

 exp = 000…0, frac ≠ 000…

 Numbers very close to 0.  Lose precision as get smaller  Equispaced

Special Values

 Condi<on: exp = 111…

 Case: exp = 111…1, frac = 000…

 Represents value ∞ (infinity)

 Opera<on that overflows

 Both posi<ve and nega<ve

 E.g., 1.0/0.0 = −1.0/−0.0 = +∞, 1.0/−0.0 = −∞

 Case: exp = 111…1, frac ≠ 000…

 Not-­‐a-­‐Number (NaN)

 Represents case when no numeric value can be determined

 E.g., sqrt(–1), ∞ − ∞, ∞ × 0

Today: Floa.ng Point

 Background: Frac<onal binary numbers

 IEEE floa<ng point standard: Defini<on

 Example and proper<es

 Rounding, addi<on, mul<plica<on

 Floa<ng point in C

 Summary

Tiny Floa.ng Point Example

 8-­‐bit Floa<ng Point Representa<on

 the sign bit is in the most significant bit

 the next four bits are the exponent, with a bias of 7

 the last three bits are the frac

 Same general form as IEEE Format

 normalized, denormalized

 representa<on of 0, NaN, infinity

s exp frac 1 4-bits 3-bits

Distribu.on of Values

 6-­‐bit IEEE-­‐like format

 e = 3 exponent bits

 f = 2 frac<on bits

 Bias is 23-­‐1-­‐1 = 3

 No<ce how the distribu<on gets denser toward zero.

8 values

s exp frac 1 3-bits 2-bits

Distribu.on of Values (close-­‐up view)

 6-­‐bit IEEE-­‐like format

 e = 3 exponent bits

 f = 2 frac<on bits

 Bias is 3

s exp frac 1 3-bits 2-bits