Docsity

Understanding Floating-Point Numbers in Computer Science: IEEE-754 Standard - Prof. Bruce , Study notes of Computer Science

Toggle sidebar
bg1
1
CS/CoE0447: Computer Organization and Assembly Language University of Pittsburgh
12
Floating-point (FP) numbers
Computers need to deal with real numbers
•Fractional numbers (e.g., 3.1416)
•Very small numbers (e.g., 0.000001)
•Very larger numbers (e.g., 2.7596
×
109)
Components in a binary FP number
•(-1)sign
×
significand (a.k.a. mantissa)
×
2exponent
•More bits in significand gives higher accuracy
•More bits in exponent gives wider range
A case for FP representation standard
•Portability issues
•Improved implementations
⇒IEEE-754
CS/CoE0447: Computer Organization and Assembly Language University of Pittsburgh
13
Representing “floats” with binary
We can add a “point” in binary notation:
•101.1010b
•integral part is simply 5d
•fractional part is 1
×
2-1 + 1
×
2-3 = 0.5 + 0.125 = 0.625
•thus, 101.1010b is 5.625d
Normal form: shift “point” so there’s only a leading 1
•101.1010b = 1.011010
×
22, shift to the left by 2 positions
•0.0001101 = 1.101
×
2-4, shift to the right by 4 positions
•typically, we use the normal form (much like scientific notation)
Just like integers, we have a choice of representation
•IEEE 754 is our focus (there are other choices, though)
pf3
pf4
pf5
pf8

Partial preview of the text

Download Understanding Floating-Point Numbers in Computer Science: IEEE-754 Standard - Prof. Bruce and more Study notes Computer Science in PDF only on Docsity!

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 12

Floating-point (FP) numbers

 Computers need to deal with real numbers

  • Fractional numbers (e.g., 3.1416)
  • Very small numbers (e.g., 0.000001)
  • Very larger numbers (e.g., 2.7596× 109 )

 Components in a binary FP number

  • (-1)sign× significand (a.k.a. mantissa )× 2 exponent
  • More bits in significand gives higher accuracy
  • More bits in exponent gives wider range

 A case for FP representation standard

  • Portability issues
  • Improved implementations ⇒ IEEE- CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 13

Representing “floats” with binary

 We can add a “point” in binary notation:

  • 101.1010b
  • integral part is simply 5d
  • fractional part is 1× 2 -1^ + 1× 2 -3^ = 0.5 + 0.125 = 0.
  • thus, 101.1010b is 5.625d  Normal form : shift “point” so there’s only a leading 1
  • 101.1010b = 1.011010 × 22 , shift to the left by 2 positions
  • 0.0001101 = 1.101 × 2 -4, shift to the right by 4 positions
  • typically, we use the normal form (much like scientific notation)  Just like integers, we have a choice of representation
  • IEEE 754 is our focus (there are other choices, though)

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 14

Format choice issues

 Example floating-point numbers (base-10)

  • 1.4× 10 -
  • -20.0 = -2.00× 101  What components do we have?  (-1)sign× significand (a.k.a. mantissa )× 2 exponent Sign Significand Exponent  Representing sign is easy (0=positive, 1=negative)  Significand is unsigned (sign-magnitude)  Exponent is a signed integer. What method do we use? CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 15

IEEE 754

 A standard for representing FP numbers in computers

  • Single precision (32 bits): 8-bit exponent, 23-bit significand
  • Double precision (64 bits): 11-bit exponent, 52-bit significand

 Leading “1” in significand is implicit (why?)

 Exponent is a signed number in biased format

  • “Biased” format – for easier sorting of FP numbers
  • All 0’s is the smallest, all 1’s is the largest
  • Bias of 127 for SP and 1023 for DP

 Hence, to obtain the actual value of a representation

  • (-1)sign×(1#”.”#significand)× 2 exponent: here “#” is concatenation
  • exponent is a biased number (see next slide)
  • exponent effectively shifts the “decimal point” in represented value sign exponent significand (or mantisa) N-1 N-2 MM-1 0

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 18

IEEE 754 example

 Let’s try 15.

  • integral part is 15d=1111b
  • fractional part is: 0.625 × 2 = 1. 25, generate the leading “1”, carry down “.25” 0.25 × 2 = 0 .5, generate the leading “0”, carry down “.5” 0.5 × 2 = 1 .0, generate the leading “1”, nothing remains “.0” answer is 0.101b
  • now, we have 1111.101b
  • normalize the result by shifting right by 3 positions 1.111101 × 23 , thus, significand = 0.111101, exponent is 3
  • get the exponent bias: 3 + 127 = 130d = 10000010b sign 8-bit exponent 23-bit significand (or mantissa) 31 30 2322 0 00 1 0 0 0 0 0 1 01 0 0 0 0 0 1 0 1 1 1 1 1 0 11 1 1 1 1 0 1 …… 0 0 00 0 0 CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 19

IEEE 754 summary

Single Precision Double Precision Represented Object Exponent Fraction Exponent Fraction 0 0 0 0 0 0 non-zero 0 non-zero +/- denormalizednumber 1~254 anything 1~2046 anything +/- floating-pointnumbers 255 0 2047 0 +/- infinity 255 non-zero 2047 non-zero NaN (Not a Number)

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 20

Denormal number

 Smallest normal (leading 1 is implicit ): 1.0× 2 Emin  Below, use “denormal” (no leading 1): 0.f× 2 Emin  e = Emin–1 , f != 0  #00000000####################### e.g., smallest without denormal 1.00000000000000000000000 x 2Emin smallest with denormal 0.00000000000000000000001 x 2- Emin- CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 21

NaN

 Not a Number  Result of illegal computation

  • 0/0, infinity/infinity, infinity – infinity, …
  • Any computation involving a NaN  e = Emax+1, f != 0  #11111111#######################  Many NaN’s

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 24

Overflow and underflow

 Overflow

  • The exponent is too large to fit in the exponent field  Underflow
  • The exponent is too small to fit in the exponent field CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 25

FP addition

(Example) 0.5ten – 0.4375ten =1.000two× 2 -1^ – 1.110two× 2 -

1. Align binary points 2. Add significands 3. Normalize result

CS/CoE0447: Computer Organization and Assembly Language (^) University of Pittsburgh 26

FP multiplication

(Example) (1.000two× 2 -1)×(-1.110two× 2 -2)

**1. Compute exponents

  1. Multiply significands
  2. Normalize result
  3. Set sign**