











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concepts of machine epsilon and rounding errors in floating point numbers. It includes examples using calculators and fortran programs, as well as an explanation of decimal and binary floating point numbers. The document also discusses chopping and rounding, and provides bounds on the relative error.
Typology: Study notes
1 / 19
This page cannot be seen from the preview
Don't miss anything!












These examples are meant to help motivate the study of machine arithmetic.
x 1 = x 2 = x 3 = 98765
There are keys on the calculator for the mean
ξ =
n
Xn j=
xj
and the standard deviation s where
s^2 =
n − 1
X^ n j=
³ ξ − xj
´ 2
In our case, what should these equal? In fact, the calculator gives
ξ = 98765 s = 1.. 58
Why?
Output: 1. 0 1. 19 E − 7 ( = 2. −^23 )
Program B:
A = 1.0 + 2. 0 ∗ ∗(−23) SILLY = 0. 0 B = A − 1. 0 P RINT ∗, A, B END Output: 1. 0 0. 0
Why the change, since presumably the variable SILLY does not have any connection to B.
We now do something similar with the binary repre- sentation of a number x. Write
x = σ · ξ · 2 e
with
1 ≤ ξ < (10) 2 = 2
and e an integer. For example,
(.1) 10 = (1. 10011001100 · · · ) 2 · 2 −^4 , σ = +
The number x is stored in the computer by storing the σ, ξ, and e. On all computers, there are restrictions on the number of digits in ξ and the size of e.
When a number x outside a computer or calculator is converted into a machine number, we denote it by f l(x). On an HP-calculator,
f l(. 3333 · · · ) = (3.333333333) 10 · 10 −^1
The decimal fraction of infinite length will not fit in the registers of the calculator, but the latter 10-digit number will fit. Some calculators actually carry more digits internally than they allow to be displayed.
On a binary computer, we use a similar notation. I will concentrate on a particular form of computer float- ing point number, that called the IEEE floating point standard.
In single precision, we write such a number as
f l(x) = σ · (1.a 1 a 2 · · · a 23 ) 2 · 2 e
What is the connection of the 24 bits in the significand ξ to the number of decimal digits in the storage of a number x into floating point form. One way of answering this is to find the integer M for which
2
This sums to 2^24 − 1. In addition, 2^24 = (1. 0 · · · 0) 2 · 224 also stores exactly. What about 2^24 + 1? It does not store exactly, as 1. (^0) | · · ·{z 0 } 23 0^0 s
2
Storing this would require 25 bits, one more than al- lowed. Thus
M = 2^24 = 16777216
This means that all 7 digit decimal integers store ex- actly, along with a few 8 digit integers.
Let y be the smallest number representable in the ma- chine arithmetic that is greater than 1 in the machine. The machine epsilon is η = y − 1. It is a widely used measure of the accuracy possible in representing num- bers in the machine.
The number 1 has the simple floating point represen- tation
1 = (1. 00 · · · 0) 2 · 20
What is the smallest number that is greater than 1? It is
1 + 2−^23 = (1. 0 · · · 01) 2 · 20 > 1
and the machine epsilon in IEEE single precision float- ing point format is η = 2−^23 = 1.. 19 × 10 −^7.
It is not too difficult to derive δ. The number 1 has the simple floating point representation
1 = (1. 00 · · · 0) 2 · 20
What is the smallest number which can be added to this without disappearing? Certainly we can write
1 + 2−^23 = (1. 0 · · · 01) 2 · 20 > 1
Past this point, we need to know whether we are us- ing chopped arithmetic or rounded arithmetic. We will shortly look at both of these. With chopped arithmetic, δ = 2−^23 ; and with rounded arithmetic, δ = 2−^24.
Let us first consider these concepts with decimal arith- metic. We write a computer floating point number z as
z = σ · ζ · 10 e^ ≡ σ · (^) (a 1 .a 2 · · · an) 10 · 10 e
with a 1 6 = 0, so that there are n decimal digits in the significand (a 1 .a 2 · · · an) 10.
Given a general number
x = σ · (a 1 .a 2 · · · an · · · ) 10 · 10 e^ , a 1 6 = 0
we must shorten it to fit within the computer. This is done by either chopping or rounding. The floating point chopped version of x is given by
f l(x) = σ · (a 1 .a 2 · · · an) 10 · 10 e
where we assume that e fits within the bounds re- quired by the computer or calculator.
Let
x = σ · (1.a 2 · · · an · · · ) 2 · 2 e
with all ai equal to 0 or 1. Then for a chopped floating point representation, we have
f l(x) = σ · (1.a 2 · · · an) 2 · 2 e
For a rounded floating point representation, we have
f l(x) = ( σ · (1.a 2 · · · an) 2 · 10 e^ an+1 = 0 σ · [(1.a 2 · · · an) 2 + (0. 0 · · · 1) 2 ] · 10 e^ an+1 = 1
The error x−f l(x) = 0 when x needs no change to be put into the computer or calculator. Of more interest is the case when the error is nonzero. Consider first the case x > 0 (meaning σ = +1). The case with x < 0 is the same, except for the sign being opposite.
With x 6 = f l(x), and using chopping, we have
f l(x) < x
and the error x − f l(x) is always positive. This later has major consequences in extended numerical com- putations. With x 6 = f l(x) and rounding, the error x − f l(x) is negative for half the values of x, and it is positive for the other half of possible values of x.
We are only giving the minimal characteristics of IEEE arithmetic. There are many options available on the types of arithmetic and the chopping/rounding. The default arithmetic uses rounding.
Single precision arithmetic:
n = 24, − 126 ≤ e ≤ 127
This results in
M = 2^24 = 16777216
η = 2−^23 = 1. 19 × 10 −^7
Double precision arithmetic:
n = 53, − 1022 ≤ e ≤ 1023
What are M and η?
There is also an extended representation, having n = 69 digits in its significand.
MATLAB can be used to generate the binary float- ing point representation of a number. Execute the command
format hex
This will cause all subsequent numerical output to the screen to be given in hexadecimal format (base 16). For example, listing the number 7 results in an output of
401 c 000000000000
The 16 hexadecimal digits are { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , a, b, c, d, e, f }. To obtain the binary representation, convert each hexadecimal digit to a four digit binary number. For the above number, we obtain the binary expansion
0100 0000 0001 1100 0000... 0000
for the number 7 in IEEE double precision floating- point format.
If you want to have a constant be DOUBLE PRECI- SION, you should make a habit of ending it with D0. For example, consider
DOUBLE PRECISION PI ... PI=3.
This will be compiled in way you did not intend. The number will be rounded to single precision length and then stored in a constant table. At run time, it will be retrieved, zeros will be appended to extend it to double precision length, and then it will be stored in PI. Instead, write
PI=3.14159265358979D