Está en la página 1de 20

Computer Architecture and Organization

Lecture 6: Floating Points

Majid Khabbazian mkhabbazian@ualberta.ca


Electrical and Computer Engineering University of Alberta

April 9, 2013

Conversion
Conversion between base 10 and base 2
Process left and right separately

Examples
a) b) c) d) 7.00 0.375 12.25 0.1

Conversion
Why it works? Let 0< a <1 How to find x-1?

. x-1 x-2 x-3 x-4

x-k

Conversion
Why it works? Let 0< a <1 How to find x-1? Compute 2a
0 . x-1 x-2 x-3 x-4 x-k x 2

Conversion
Why it works? Let 0< a <1 How to find x-1? Compute 2a
0 . x-1 x-2 x-3 x-4 x-k x-k x 2

x-1 . x-2 x-3 x-4

Representable Numbers
Each base has numbers that are not representable with finite number of digits
Decimal
Finite: 1/10 = 0.1 Infinite: 1/3 = 0.33 [3]

Base 3
Finite: 1/3 = 0.1 Infinite: 1/10 = 0.00220022 [0022]

Binary
Finite: 1/2 = 0.1 Infinite: 1 / 3 = 0.0101 [01]

Limitation is acceptable (usually, an approximation is sufficient)

Floating Point
Finite-length encodings cannot represent numbers such as 1/3 and 5/7
Fractional binary notation can only represent numbers in the form V = M 2E Examples:
a) 7 x 24 = b) 9 x 214 = c) 21 x 223 =

Floating Point
More examples:
a) 5 2-3 = 5/8 = b) 5 2-4 = 5/16 = c) 5 2-8 = 5/256 =

Notice: E determines location of point


Hence: floating point notation

Advantage: Only need to store M and E

A simple fact
We can write any positive binary number in the normalized form: 1.b1b2b3. x 2E
Examples: 1101.01 = 0.0010101 =

Floating Point Representation


Encode values as (-1)s M 2E
Sign bit s
determines whether number is negative or positive

Significand M
Exponent E

Floating Point Representation


Encode values as (-1)s M 2E
Sign bit s
determines whether number is negative or positive

Significand M
Exponent E
s
exp

frac

Floating Point Representation


Bit representation
Single bit encodes sign exp contains k bits encoding E frac contains n bits encoding M

Standards
Single precision: 8 exp bits, 23 frac bits
32 bits total

Double precision: 11 exp bits, 52 frac bits


64 bits total

exp

frac

Decoding: Normalized Form


Case #1: exp is neither all zeros nor all ones

s
s ek-1

exp e1 e0 fn-1 fn-2

frac
f2 f1 f0

Normalized Form
Examples:
a) b) c) d) k=2, n=3: k=3, n=4: K=3, n=4: k=4, n=?: 101101 01011100 10110011 01001010111

s
s ek-1

exp e1 e0 fn-1 fn-2

frac
f2 f1 f0

Decoding: Denormalized Form


Case #2: exp is all zeros

s
s 0

exp 0 0 fn-1 fn-2

frac
f2 f1 f0

Denormalized Form
Examples:

a) k=2, n=3: 100101


b) k=3, n=4: 00001100 c) K=3, n=?: 10000011

s
s ek-1

exp e1 e0 fn-1 fn-2

frac
f2 f1 f0

Decoding: Special Values


Case #3: exp is all ones
Situation #1: f=0
a) s=0 + b) s=1 -

Situation #2: f0
NAN (Not a Number)

s
s 1

exp 1 1 fn-1 fn-2

frac
f2 f1 f0

More Examples
k=3, n=4
a) 10001001= b) 11110000= c) 01110100= d) 01110000=

e) 01010101=

18

Non-negative floating-point numbers


k=4, n=5
a) Zero? b) Smallest positive denormalized number? c) Largest denormalized number? d) Smallest positive normalized number?

e) Largest normalized number?


f) One?
19

Floating point: Encoding


Explaining through examples
Let k=4 and n=4 Positive numbers in base 2
a) 1.0111 b) 1010.1001

20

También podría gustarte