Docsity

Floating Point Arithmetic: IEEE754 Standard and Representation, Study notes of Computer Science

Toggle sidebar
bg1
ECS231 Handout 2 Floating Point Arithmetic April 2, 2009
1. Floating point representation (scientific notation) of numbers, for example,
−3.1416 ×101
↑
sign
↑
significand
↑
base
←exponent
2. Computers use binary arithmetic, representing each number as a binary num-
ber. The floating point representation of a nonzero binary number xis of the
form
x=±b0.b1b2···bp−1×2E.(1)
(a) It is normalized, i.e., b0= 1 (the hidden bit)
(b) Precision (= p) is the number of bits in the significand (mantissa) (in-
cluding the hidden bit).
(c) Machine epsilon ǫ= 2−(p−1), the gap between the number 1 and the
smallest floating point number that is greater than 1.
(d) The unit in the last place, ulp(x) = 2−(p−1) ×2E=ǫ×2E.
If x > 0, then ulp(x) is the gap between xand the next larger floating
point number. If x < 0, then ulp(x) is the gap between xand the smaller
floating point number (larger in absolute value).
3. Special numbers: 0, −0, ∞,−∞, NaN = “Not a Number”.
4. IEEE754 floating point standard (IEEE 1987) essentials:
•consistent representation of floating point numbers by all machines adopt-
ing the standard;
•correctly rounded floating point operations, using various rounding modes;
•consistent treatment of exceptional situation such as division by zero.
5. IEEE single format takes 32 bits long (= 4 bytes):
s E f
sign exponent
t
binary point fraction
←− −→8←− −→23
It represents the number
(−1)s·(1.f)×2E−127
Note that the leading 1 in the fraction need not be stored explicitly, because
it is always 1. This hidden bit accounts for the “1.” here. The “E−127” in
the exponent is to avoid the need for storage of a sign bit.
The range of positive normalized numbers is from
Nmin = 1.00 ···0×2−126 = 2−126 ≈1.2×10−38
to
Nmax = 1.11 ···1×2127 = (2 −2−23 )×2127 ≈2128 ≈3.4×1038.
1
pf3
pf4

Partial preview of the text

Download Floating Point Arithmetic: IEEE754 Standard and Representation and more Study notes Computer Science in PDF only on Docsity!

ECS231 Handout 2 Floating Point Arithmetic April 2, 2009

  1. Floating point representation (scientific notation) of numbers, for example, − 3. 1416 × 101 ↑ sign

significand

base

← exponent

  1. Computers use binary arithmetic, representing each number as a binary num- ber. The floating point representation of a nonzero binary number x is of the form x = ± b 0 .b 1 b 2 · · · bp− 1 × 2 E^. (1) (a) It is normalized, i.e., b 0 = 1 (the hidden bit) (b) Precision (= p) is the number of bits in the significand (mantissa) (in- cluding the hidden bit). (c) Machine epsilon ǫ = 2−(p−1), the gap between the number 1 and the smallest floating point number that is greater than 1. (d) The unit in the last place, ulp(x) = 2−(p−1)^ × 2 E^ = ǫ × 2 E^. If x > 0, then ulp(x) is the gap between x and the next larger floating point number. If x < 0, then ulp(x) is the gap between x and the smaller floating point number (larger in absolute value).
  2. Special numbers: 0, −0, ∞, −∞, NaN = “Not a Number”.
  3. IEEE754 floating point standard (IEEE 1987) essentials:
    • consistent representation of floating point numbers by all machines adopt- ing the standard;
    • correctly rounded floating point operations, using various rounding modes;
    • consistent treatment of exceptional situation such as division by zero.
  4. IEEE single format takes 32 bits long (= 4 bytes):

s E f sign exponent

t binary point fraction

It represents the number (−1)s^ · (1.f ) × 2 E−^127 Note that the leading 1 in the fraction need not be stored explicitly, because it is always 1. This hidden bit accounts for the “1.” here. The “E − 127” in the exponent is to avoid the need for storage of a sign bit. The range of positive normalized numbers is from Nmin = 1. 00 · · · 0 × 2 −^126 = 2−^126 ≈ 1. 2 × 10 −^38 to Nmax = 1. 11 · · · 1 × 2127 = (2 − 2 −^23 ) × 2127 ≈ 2128 ≈ 3. 4 × 1038.

  1. Special repsentations for 0, ±∞ and NaN:

zero = ± 00000000 00000000000000000000000

±∞ = ± 11111111 00000000000000000000000

NaN = ± 11111111 otherwise

  1. IEEE double format takes 64 bits long (=8 bytes):

s E f sign exponent

t binary point fraction

It represents the numer (−1)s^ · (1.f ) × 2 E−^1023

The range of positive normalized numbers is from Nmin = 2−^1022 ≈ 2. 2 × 10 −^308 to Nmax = 1. 11 · · · 1 × 21023 ≈ 21024 ≈ 1. 8 × 10308.

Special repsentations for 0, ±∞ and NaN.

  1. IEEE extended format, with at least 15 bits available for the exponent and at least 63 bits for the fractional part of the significant. (Pentium has 80-bit extended format)
  2. Precision and machine epsilon of the IEEE formats Format Precision p Machine epsilon ǫ = 2−p−^1 single 24 ǫ = 2−^23 ≈ 1. 2 × 10 −^7 double 53 ǫ = 2−^52 ≈ 2. 2 × 10 −^16 extended 64 ǫ = 2−^63 ≈ 1. 1 × 10 −^19
  3. Rounding

Let a positive real number x is in the normalized range, i.e., Nmin ≤ x ≤ Nmax, and write in the normalized form x = (1.b 1 b 2 · · · bp− 1 bpbp+1.. .) × 2 E^ , Then the closest floating point number less than or equal to x is x− = 1.b 1 b 2 · · · bp− 1 × 2 E^ , i.e., x− is obtained by truncating. The next floating point number bigger than x− is x+ = ((1.b 1 b 2 · · · bp− 1 ) + (0. 00 · · · 01)) × 2 E^ , therefore, also the next one that bigger than x. If x is negative, the situtation is reversed. Correctly rounding modes:

D. Goldberg. What every computer scientist should know about floating- point arithmetic. ACM Computing Surveys, 18(1):5–48, 1991.

The following recent published textbook gives a broad overview of numerical computing, with special focus on the IEEE standard for binary floating point arithmetic.

M. Overton. Numerical computing with IEEE floating point arithemetic. SIAM, Philadelphia, 2001. ISBN 0-89871-482-6. Student price $20. directly from www.siam.org.