Presentation is loading. Please wait.

Presentation is loading. Please wait.

Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or.

Similar presentations


Presentation on theme: "Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or."— Presentation transcript:

1 Floating Point Numbers

2 CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or 2 64 numbers to be represented. Which reals to represent? There are an infinite number between 2 adjacent integers. (or two reals!!) Which bit patterns for reals selected? Answer: use scientific notation

3 CMPE12cGabriel Hugh Elkaim 3 ABA x 10 B 0any0 1.. 901.. 9 1.. 9110.. 90 1.. 92100.. 900 1.. 9-10.1.. 0.9 1.. 9-20.01.. 0.09 Consider: A x 10 B, where A is one digit How to do scientific notation in binary? Standard: IEEE 754 Floating-Point Floating Point Numbers

4 CMPE12cGabriel Hugh Elkaim 4

5 CMPE12cGabriel Hugh Elkaim 5 IEEE 754 Single Precision Floating Point Format Representation: SEF S is one bit representing the sign of the number E is an 8 bit biased integer representing the exponent F is an unsigned integer The true value represented is:(-1) S x f x 2 e S = sign bit e = E – bias f = F/2 n + 1 for single precision numbers n=23, bias=127

6 CMPE12cGabriel Hugh Elkaim 6 S, E, F all represent fields within a representation. Each is just a bunch of bits. S is the sign bit (-1) S  (-1) 0 = +1 and (-1) 1 = -1 Just a sign bit for signed magnitude E is the exponent field The E field is a biased-127 representation. True exponent is (E – bias) The base (radix) is always 2 (implied). Some early machines used radix 4 or 16 (IBM) IEEE 754 Single Precision Floating Point Format

7 CMPE12cGabriel Hugh Elkaim 7 F (or M) is the fractional or mantissa field. It is in a strange form. There are 23 bits for F. A normalized FP number always has a leading 1. No need to store the one, just assume it. This MSB is called the HIDDEN BIT. IEEE 754 Single Precision Floating Point Format

8 CMPE12cGabriel Hugh Elkaim 8 How to convert 64.2 into IEEE SP 1.Get a binary representation for 64.2 Binary of left of radix pointis: Binary of right of radix.2 x 2 = 0.40.4 x 2 = 0.80.8 x 2 = 1.61.6 x 2 = 1.21 Binary for.2: 64.2 is: 2.Normalize binary form Produces:

9 CMPE12cGabriel Hugh Elkaim 9 Floating Point Since floating point numbers are always stored in normal form, how do we represent 0? 0x0000 0000 and 0x8000 0000 represent 0. What numbers cannot be represented because of this? 3. Turn true exponent into bias-127 4. Put it together: 23-bit F is: S E F is: In hex:

10 CMPE12cGabriel Hugh Elkaim 10 Another Conversion Example 178.125 in SP FP?

11 CMPE12cGabriel Hugh Elkaim 11

12 CMPE12cGabriel Hugh Elkaim 12 Conversion Process

13 CMPE12cGabriel Hugh Elkaim 13 IEEE Floating Point Format Other special values: + 5 / 0 = + ∞ + ∞ = 0 11111111 00000… (0x7f80 0000) -7/0 = - ∞ - ∞ = 1 11111111 00000… (0xff80 0000) 0/0 or + ∞ + - ∞ = NaN (Not a number) NaN ? 11111111 ?????… (S is either 0 or 1, E=0xff, and F is anything but all zeroes) Also de-normalized numbers (beyond scope)

14 CMPE12cGabriel Hugh Elkaim 14 Another way of looking at it

15 CMPE12cGabriel Hugh Elkaim 15 IEEE Floating Point What is the decimal value for this SP FP number 0x4228 0000?

16 CMPE12cGabriel Hugh Elkaim 16 IEEE Floating Point What is 47.625 10 in SP FP format?

17 CMPE12cGabriel Hugh Elkaim 17

18 CMPE12cGabriel Hugh Elkaim 18 Questions?


Download ppt "Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or."

Similar presentations


Ads by Google