Professional Documents
Culture Documents
1st Machine Numbers Computer Arithmetic and Errors
1st Machine Numbers Computer Arithmetic and Errors
1st Machine Numbers Computer Arithmetic and Errors
Example
Example
Example
5.25 = 22 + 20 + 2−2
has an exact representation in finite binary (base 2) system. However,
1
= 2−2 + 2−4 + 2−6 + . . .
3
does not.
A floating-point number, the way a real number represented in
computers, approximates the real number.
Example
(10101.0111)2 = (1.01010111)2 · 24
Example
x xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx
sign(1) exponent (8) mantissa (23)
x xxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx. . . x
sign(1) exponent (11) mantissa (52)
s = σ · (1.a1 a2 . . . a23 ) · 2n
σ and ai values are binary numbers already. The exponent field needs to
represent both positive and negative exponents. Exponents in the interval
[0, 126] have negative sing and those in [128, 255] have positive sign. A
bias (127) is added to the actual exponent in order to get the stored
exponent. Letting k be the number of reserved bits for the exponent, the
bias can be found by 2k−1 − 1. (28−1 − 1 = 127 in this particular case.)
1
Not a Number
Dr. Mustafa Ağgül Hacettepe University
Machine Numbers
MAT307 Numerical Analysis Errors and Computer Arithmetics
Stability
Example
1= 00111111100000000000000000000000 = +1.0 × 2127−127
−2 = 11000000000000000000000000000000 = −1.0 × 2128−127
0.03515625 = 00111101000100000000000000000000 = +1.125 × 2122−127
264.03125 = 01000011100001000000010000000000 = +1.0313720703125 × 2135−127
I The mantissa,
Definition
We denote the machine floating-point representation of s by f l(s).
I truncate or chop d to n binary digits, ignoring the remaining digits
I round d to n binary digits, based on the size of the part of d
following digit n:
a) if n + 1st digit is 0, chop d to n digits
b) if n + 1st digit is 1, chop d to n digits and add 1 to the last
digit of the result
Definition
I The error in an approximated quantity is defined as
E(sA ) = |sT − sA |
E(d2A )
Rel(d2A ) = = 0.50 = 50%
d2T
When doing calculations with numbers that contain an error, the result
will be effected by these errors. This phenomenon is called the
propagation of error. For example, let
Remark
Rel(xy) = Rel(x) + Rel(y).
Example
Finding the roots of ax2 + bx + c = 0 by quadratic formula
√ √
−b + b2 − 4ac −b − b2 − 4ac
x1 = and x2 =
2a 2a
is unstable if b2 >> |4ac|.
√
I if b ≤ 0, cancellation occurs in x2 since −b ≈ b2 − 4ac
√
I if b ≥ 0, cancellation occurs in x1 since b ≈ b2 − 4ac
in both cases b may be exact, but the square root introduces errors.