12.07.2015 Views

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

computational science basics 23the maximum value for f:X max = 01111 1111 1111 1111 1111 1111 1111 111= (0)(1111 1111)(1111 1111 1111 1111 1111 111), (1.6)where we have grouped the bits for clarity. After putting all the pieces together, weobtain the value shown in Table 1.4:s =0, e= 1111 1110 = 254, p= e − 127 = 127,f =1.1111 1111 1111 1111 1111 111 = 1 + 0.5+0.25 + ···≃2,⇒ (−1) s × 1.f × 2 p=e−127 ≃ 2 × 2 127 ≃ 3.4 × 10 38 . (1.7)Likewise, the smallest positive floating-point number possible is subnormal (e =0)with a single significant bit in the mantissa:This corresponds to0 0000 0000 0000 0000 0000 0000 0000 001.s =0, e=0, p= e − 126 = −126f =0.0000 0000 0000 0000 0000 001 = 2 −23⇒ (−1) s × 0.f × 2 p=e−126 =2 −149 ≃ 1.4 × 10 −45 (1.8)In summary, single-precision (32-bit or 4-byte) numbers have six or seven decimalplaces of significance and magnitudes in the range1.4 × 10 −45 ≤ single precision ≤ 3.4 × 10 38Doubles are stored as two 32-bit words, for a total of 64 bits (8 B). The signoccupies 1 bit, the exponent e, 11 bits, and the fractional mantissa, 52 bits:s e f f (cont.)Bit position 63 62 52 51 32 31 0As we see here, the fields are stored contiguously, with part of the mantissa f storedin separate 32-bit words. The order of these words, and whether the second wordwith f is the most or least significant part of the mantissa, is machine- dependent.For doubles, the bias is quite a bit larger than for singles,Bias = 1111111111 2 = 1023 10 ,so the actual exponent p = e − 1023.The bit patterns for doubles are given in Table 1.6, with the range andprecision given in Table 1.4. To repeat, if you write a program with doubles, then−101<strong>COPYRIGHT</strong> <strong>2008</strong>, PRINCET O N UNIVE R S I T Y P R E S SEVALUATION COPY ONLY. NOT FOR USE IN COURSES.ALLpup_06.04 — <strong>2008</strong>/2/15 — Page 23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!