Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 210 Computer Organization

Similar presentations


Presentation on theme: "Computer Science 210 Computer Organization"— Presentation transcript:

1 Computer Science 210 Computer Organization
Floating Point Representation

2 Why “Floating Point” ? For many applications (e.g., banking) it’s okay to have a fixed position for the decimal point: $2.99, $101.23, etc., where decimal point is always to places from the right. In applications where we need more precision (e.g., scientific computing), we need the decimal point to “float” around in the number: , , , etc.

3 Real Numbers Format 1: <whole part>.<fractional part>
Examples: , … Format 2 (normalized form): <digit>.<fractional part> × <exponent> Example: × 10-1 In mathematics, infinite range and infinite precision (“uncountably infinite”)

4 math.pi Looks like about 48 places of precision (in base10)
>>> import math >>> math.pi >>> print(math.pi) >>> print("%.50f" % math.pi) Looks like about 48 places of precision (in base10)

5 IEEE Standard Single precision: 32 bits Double precision: 64 bits
2.5 × 10-1 Reserve some bits for the significand (the digits to the left of ×) and some for the exponent (the stuff to the right of ×) Double precision uses 52 bits for the significand, 11 bits for the exponent, and one sign bit Approximate double precision range is to 10308

6 IEEE Single Precision Format
32 bits Roughly (-1)S x F x 2E F is related to the significand E is related to the exponent Rough range Small fractions 2 x 10-38 Large fractions 2 x 1038 S Exponent Significand

7 Fractions in Binary In general, 2-N = 1/2N
0.12 = 1 × 2-1 = 1 × ½ = 0.510 0.012 = 1 × 2-2 = 1 × ¼ = 0.112 = 1 × ½ + 1 × ¼ =

8 Decimal to Binary Conversion (Whole Numbers)
While N > 0 do Set N to N/2 (whole part) Record the remainder (1 or 0) Set A to remainders in reverse order

9 Decimal to Binary - Example
Example: Convert to binary N Rem N Rem 32410 =

10 Decimal to Binary - Fractions
While fractional part > 0 do Set N to N*2 (whole part) Record the whole number part (1 or 0) Set N to fraction part Set bits to sequence of whole number parts (in order obtained)

11 Decimal fraction to binary - Example
Example: Convert to binary N Whole Part =

12 Decimal fraction to binary - Example
Example: Convert to binary N Whole Part = …2

13 Round-Off Errors Caused by conversion of decimal fractions to binary
>>> 0.1 0.1 >>> print("%.48f" % 0.1) >>> print("%.48f" % 0.25) >>> print("%.48f" % 0.3) Caused by conversion of decimal fractions to binary

14 Scientific Notation - Decimal
Number Normalized Scientific x ,326,043, x 109

15 Floating Point IEEE 754 Single Precision Standard (32 bits)
Roughly (-1)S x F x 2E F is related to significand E is related to exponent Rough range Small fractions 2 x 10-38 Large fractions 2 x 1038 S Exponent Significand

16 Floating Point – Exponent Field
This comes before significand for sorting purposes With 8 bit exponent range would be –128 to 127 Note: -1 would be and with simple sorting would appear largest. For this reason, we take the exponent, add 127 and represent this as unsigned. This is called bias 127. Then exponent field (255) would represent = 128. Also (0) would represent = -127. Range of exponents is -127 to 128

17 Floating Point – Significand
Normalized form: … x 2E Hidden bit trick: Since the bit to left of binary point is always 1, why store it? We don’t. Number = (-1)S x (1+Significand) x 2E-127

18 Floating Point Example: Convert 312.875 to IEEE
Step 1. Convert to binary: Step 2. Normalize: x 28 Step 3. Compute biased exponent in binary: = 135  Step 4. Write the floating point representation: or 439C7000 in hexadecimal

19 Floating Point Example: Convert IEEE 11000000101000… to decimal
Step 1. Sign bit is 1; so number is negative Step 2. Exponent field is or 129; so actual exponent is 2 Step 3. Significand is …; so 1 + Significand is … Step 4. Number = (-1)S x (1+Significand) x 2E-127 = (-1)1 x (1.010) x 22 = -101 = -5

20 For Next Time Section 2.6: Boolean Algebra
Sections 3.1, 3.2: Transistors and Logic Gates


Download ppt "Computer Science 210 Computer Organization"

Similar presentations


Ads by Google