+ All Categories
Home > Documents > Floating-Point Representation We can store integers and characters easily in binary, but what about...

Floating-Point Representation We can store integers and characters easily in binary, but what about...

Date post: 05-Jan-2016
Category:
Upload: susan-bryant
View: 212 times
Download: 0 times
Share this document with a friend
21
Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ = .25 = 2.5 * 10 -1 9.1093897 * 10 -31 – m e- - mass of an electron 1.6021733 * 10 -19 – e – charge of an electron 6.6260755 * 10 -34 – h – plank’s constant What are the components of the above #’s? 1. 2. 3. 4.
Transcript
Page 1: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Floating-Point Representation

• We can store integers and characters easily in binary, but what about fractions?

• ¼ = .25 = 2.5 * 10-1

• 9.1093897 * 10-31 – me-- mass of an electron

• 1.6021733 * 10-19 – e – charge of an electron• 6.6260755 * 10-34 – h – plank’s constant• What are the components of the above #’s?

1.

2.

3.

4.

Page 2: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Moving to Binary

• 9.1093897 * 10-31 – me-- mass of an electron

• What would the equivalent be in binary?

• ___________

Sign Exponent Significand

Single Precision

1 bit 8 bits 23 bits

Double Precision

1 bit 11 bits 52 bits

Page 3: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Interpreting Floating-point

• 9.471 = 9 + 4*.1 + 7*.01 + 1*.001

• The ith bit to the right of the decimal point of a decimal number represents______

• The ith bit to the right of the decimal point of a binary number represents _______

Page 4: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Translating to Binary

1. Translate left of decimal normally

2. Translate the right of the decimal a. bit-by-bit *or*

b. Express as fraction, x/ 2y, and place x in y bits, filling to the left with 0’s.

3. Multiply by 2y to move decimal to proper position.

Page 5: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Example 1 – Translate the

7.75 =

-1/4 =

¼ =

Page 6: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

following numbers into binary fp

Sign Exp Significand

Page 7: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Bias Notation

• Problem: Negative exponents have larger value than positive exponents

• Solution: – Adjust exponent range

– add ____ to all exponents

Page 8: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Sign Exp Significand0 0..010 11110….000

1 1..110 00000….000

0 11110….000

1 00000….000

7.75

-1/4

1/4

7.75

-1/4

1/4

No Bias

Bias

Page 9: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Floating-Point Addition

• How do we do decimal floating-point?

• Is it the same as integer addition?

• 7.5 + 3/8

Page 10: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Steps to floating-point addition

1. Right-shift _________ of smaller exponent until exponents match

2. Add the __________

3. ______ to adjust decimal point

4. Round the result to fit into the significand

Page 11: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Example 1: 7.5 + ¾1.111two * 22 + 1.1two * 2-1

Page 12: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Example 2: 1.1two * 2-96 + 1.0two * 22

Page 13: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Associative property

• (a + b) + c < == > a + (b + c)

Page 14: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

a + (b + c)

• 1.1two * 2-96 + 1.0two * 22 +-1.0two * 22

Page 15: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

(a + b) + c

• (1.1two * 2-96 + 1.0two * 22 )+ -1.0two * 22

Page 16: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Multiplication

• 1.111two * 22 * 1.1two * 2-2

Page 17: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Multiplication

1. ________ exponents

2. ________ significands

3. ________ decimal point

4. ________ answer

5. determine the _______

Page 18: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

What about bias notation?

• 1.111two * 2129 * 1.1two * 2-125

Page 19: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Thought question

• Some computers have separate fp and integer register files

• Most instructions access only int or fp, not both.

• How is this different from doubling the size of the register file?

• What are the advantages? Disadvantages?

Page 20: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Thought question

Page 21: Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * 10 -1 9.1093897 * 10 -31.

Summary

• Floating-point greatly increases range of numbers stored in machine.

• Floating-point representation has limited precision – can not store every number in range.

• FP arithmetic sometimes rounds answers, violating algebraic properties.

• FP arithmetic is much slower than integer arithmetic.


Recommended