Floating Point Representations IT 110 Computer Organization Floating

  • Slides: 20
Download presentation
Floating Point Representations IT 110: Computer Organization

Floating Point Representations IT 110: Computer Organization

Floating Point Number Representations How to deal with fractions – Fractions (or decimals) are

Floating Point Number Representations How to deal with fractions – Fractions (or decimals) are difficult to represent in computing systems because they must represent very large and small numbers in the same format and they can be written in many different ways. – Example: ‐ 357. 02186 can be written as ‐ 0. 00035706186× 105 or ‐ 3570216. 6× 10‐ 4. – Must normalize the representation somehow, e. g. , as SEEMMMMM IT 110: Computer Organization

Floating Point Number Representations How to deal with fractions – Fractions (or decimals) are

Floating Point Number Representations How to deal with fractions – Fractions (or decimals) are difficult to represent in computing systems because they must represent very large and small numbers in the same format and they can be written in many different ways. – Example: ‐ 357. 02186 can be written as ‐ 0. 00035706186× 105 or ‐ 3570216. 6× 10‐ 4. – Must normalize the representation somehow, e. g. , as SEEMMMMM S: Sign (0 is positive, 1 is negative) E: The exponent M: The digits of the mantissa IT 110: Computer Organization

Floating Point Number Representations How to deal with fractions – The exponent can be

Floating Point Number Representations How to deal with fractions – The exponent can be positive or negative. Subtract half of the range from the encoded number to get the real exponent. – e. g. , for a 2‐digit exponent (00‐ 99), half is 50. An exponent encoded as 34 would actually be 34 ‐ 50 = ‐ 26. – This is called excess notation. The example above is excess‐ 50. IT 110: Computer Organization

Floating Point Number Representations How to deal with fractions – The exponent can be

Floating Point Number Representations How to deal with fractions – The exponent can be positive or negative. Subtract half of the range from the encoded number to get the real exponent. Example: Normalize – e. g. , for a 2‐digit exponent (00‐ 99), half is 50. An exponent encoded as 34 would actually be 34 ‐ 50 = ‐ 26. ‐ 357. 02186 in this way. – This is called excess notation. The example above is excess‐ 50. IT 110: Computer Organization

Floating Point Number Representations How to deal with fractions – The exponent can be

Floating Point Number Representations How to deal with fractions – The exponent can be positive or negative. Subtract half of the range from the encoded number to get the real exponent. Example: Normalize – e. g. , for a 2‐digit exponent (00‐ 99), half is 50. An exponent encoded as 34 would actually be 34 ‐ 50 = ‐ 26. ‐ 357. 02186 in this way. – This is called excess notation. The example above is excess‐ 50. ‐. 35702186× 103 Shift decimal IT 110: Computer Organization

Floating Point Number Representations How to deal with fractions – The exponent can be

Floating Point Number Representations How to deal with fractions – The exponent can be positive or negative. Subtract half of the range from the encoded number to get the real exponent. Example: Normalize – e. g. , for a 2‐digit exponent (00‐ 99), half is 50. An exponent encoded as 34 would actually be 34 ‐ 50 = ‐ 26. ‐ 357. 02186 in this way. – This is called excess notation. The example above is excess‐ 50. ‐. 35702186× 103 Shift decimal Truncate ‐. 35702× 103 IT 110: Computer Organization

Floating Point Number Representations How to deal with fractions – The exponent can be

Floating Point Number Representations How to deal with fractions – The exponent can be positive or negative. Subtract half of the range from the encoded number to get the real exponent. Example: Normalize – e. g. , for a 2‐digit exponent (00‐ 99), half is 50. An exponent encoded as 34 would actually be 34 ‐ 50 = ‐ 26. ‐ 357. 02186 in this way. – This is called excess notation. The example above is excess‐ 50. ‐. 35702186× 103 Shift decimal Truncate ‐. 35702× 103 Encode 15335702 IT 110: Computer Organization

Floating Point Number Representations How to deal with fractions – Computing systems use base

Floating Point Number Representations How to deal with fractions – Computing systems use base 2 rather than base 10 encodings for floating point numbers. – IEEE 754 single precision (32‐bit) floating point format 1 8 23 Excess S Mantissa 128 – Mantissa is encoded using fractional powers of 2, thus 2‐ 1, 2‐ 2, 2‐ 3, 2‐ 4, etc. IT 110: Computer Organization

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find sign, make positive Negative (1), 357. 02186 Convert to a power of 2 357. 02186 = 1. 3946166406× 28 Extract exponent 8 Convert to excess 128 8 + 127 = 135 = 100001112 Drop leading 1 0. 3946166406 Rewrite as sum of fractional powers of 2 Rewrite mantissa 0110010100000101100 Combine fields 1100 0011 1011 0010 1000 0010 1100 IT 110: Computer Organization

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find sign, make positive Negative (1), 357. 02186 Convert to a power of 2 357. 02186 = 1. 3946166406× 28 Extract exponent 8 Convert to excess 128 8 + 127 = 135 = 100001112 Drop leading 1 0. 3946166406 Rewrite as sum of fractional powers of 2 Rewrite mantissa 0110010100000101100 Combine fields 1100 0011 1011 0010 1000 0010 1100 IT 110: Computer Organization

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find sign, make positive Negative (1), 357. 02186 Convert to a power of 2 357. 02186 = 1. 3946166406× 28 Extract exponent 8 Convert to excess 128 8 + 127 = 135 = 100001112 Drop leading 1 0. 3946166406 Rewrite as sum of fractional powers of 2 Rewrite mantissa 0110010100000101100 Combine fields 1100 0011 1011 0010 1000 0010 1100 IT 110: Computer Organization

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find sign, make positive Negative (1), 357. 02186 Convert to a power of 2 357. 02186 = 1. 3946166406× 28 Extract exponent 8 Convert to excess 128 8 + 127 = 135 = 100001112 Drop leading 1 0. 3946166406 Rewrite as sum of fractional powers of 2 Rewrite mantissa 0110010100000101100 Combine fields 1100 0011 1011 0010 1000 0010 1100 IT 110: Computer Organization

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find sign, make positive Negative (1), 357. 02186 Convert to a power of 2 357. 02186 = 1. 3946166406× 28 Extract exponent 8 Convert to excess 128 8 + 127 = 135 = 100001112 Drop leading 1 0. 3946166406 Rewrite as sum of fractional powers of 2 Rewrite mantissa 0110010100000101100 Combine fields 1100 0011 1011 0010 1000 0010 1100 IT 110: Computer Organization

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find sign, make positive Negative (1), 357. 02186 Convert to a power of 2 357. 02186 = 1. 3946166406× 28 Extract exponent 8 Convert to excess 128 8 + 127 = 135 = 100001112 Drop leading 1 0. 3946166406 Rewrite as sum of fractional powers of 2 Rewrite mantissa 0110010100000101100 Combine fields 1100 0011 1011 0010 1000 0010 1100 IT 110: Computer Organization

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find sign, make positive Negative (1), 357. 02186 Convert to a power of 2 357. 02186 = 1. 3946166406× 28 Extract exponent 8 Convert to excess 128 8 + 127 = 135 = 100001112 Drop leading 1 0. 3946166406 Rewrite as sum of fractional powers of 2 Rewrite mantissa 0110010100000101100 Combine fields 1100 0011 1011 0010 1000 0010 1100 IT 110: Computer Organization

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find

Floating Point Number Representations Example – Encode ‐ 357. 02186 using IEEE 754. Find sign, make positive Negative (1), 357. 02186 Convert to a power of 2 357. 02186 = 1. 3946166406× 28 Extract exponent 8 Convert to excess 128 8 + 127 = 135 = 100001112 Drop leading 1 0. 3946166406 Rewrite as sum of fractional powers of 2 Rewrite mantissa 0110010100000101100 Combine fields 1100 0011 1011 0010 1000 0010 1100 IT 110: Computer Organization

Floating Point Number Representations Why go to all this effort for floating point representations?

Floating Point Number Representations Why go to all this effort for floating point representations? – Simplification of CPU hardware for addition and subtraction of floating point. – Case 1: When exponents are the same, simple binary add or subtract of the mantissa works. – Case 2: If exponents differ, a left or right shift of the mantissa bits by the exponent difference yields case 1. IT 110: Computer Organization

Floating Point Number Representations Why go to all this effort for floating point representations?

Floating Point Number Representations Why go to all this effort for floating point representations? – Simplification of CPU hardware for addition and subtraction of floating point. – Case 1: When exponents are the same, simple binary add or subtract of the mantissa works. – Case 2: If exponents differ, a left or right shift of the mantissa bits by the exponent difference yields case 1. Main point: internal representations (IEEE 754, two’s complement, etc. ) are about making the CPU fast and inexpensive. IT 110: Computer Organization

Signed Integer Representations Summary – Converting decimal floating point to binary floating point is

Signed Integer Representations Summary – Converting decimal floating point to binary floating point is non‐trivial. – Representations as a sign, excess‐n exponent, and fractional binary mantissa. – End goal is a representation that is fast to manipulate in the CPU. IT 110: Computer Organization