Exercise for today's lab:
The sample code from p. 77 (textp77.f) of our text is available
to you today. You should make a new directory and copy all the sample codes
to this directory.
cp ~stewart/cs575/fall02/testmachine/* .
Do not forget the final space dot in the 3 commands above.
Compile the code and then run it in your account using
f90 textp77.f -o textp77
textp77
Examine the effect of 8 byte floating point arithmetic
As directed in the text, edit the code (using vi or
pico) and change the declarations of the floating
point variables to be REAL*8 instead of REAL*4.
I suggest calling the new code text8p77.f or some sort
of different name. Recompile and execute the commands, suitably
modified, from above.
As evidence of active learning in lab today, you
must email stewart@rohan.sdsu.edu the number of
non-perfect inverses for 4 byte and 8 byte
arithmetic that you discovered today from running the code.
It is unfortunate, but there are few numeric inquiry capabilities in
C and C++ to support Scientific Computing. We have focussed on Fortran 90
because this language is well supported by compilers and other tools.
The design of the language
incorporates many features to assist computational scientists
and their programming needs.
There are additional examples of floating point behavior available
to you in the sample codes you have just copied to your own class account.
Each one has its own "link" file to make it simpler for you to construct
your own examples of floating point constants.
- simple.f using link-sim
- Computer the computer's unit roundoff, u, the largest value
so that 1.0 + u = 1.0
- simpledp.f using link-dpsim
- Computer the computer's unit roundoff, u, in double precision
arithmetic.
- machar.f using link-ma
- This code actually computes the machine constants.
This code was written by W.J. Cody of Argonne National Laboratory,
as part of the MINPACK software development, March 1980.
Note: the link file (link-ma) in this suite of codes uses f77,
since f90 is unable to produce an executable. There is an IEEE
floating-point exception raised by the f90 compiler and no
executable is produced. But the f77 compiler computes most of
the constants before failing on XMAX = Inf and generating the
IEEE warning.
ACM TOMS Algorithm 768
(a UNIX sh-archive)
- testnum.f, machcon.f and xerror.f using link-num
- This code uses a data statement to initialize the constants. You
need to be lucky enough that the computing platform you use already
had its values coded in r1mach, d1mach and i1mach. You can examine the
source code and see the wide variety of computers that were provided for -
before the days of the IEEE 754 Floating Point Standard.
Do you know of Scientific Computing in C or C++ examples?
Numerical Recipes [commercial product, not recommended by instructor]
(But thanks to Randy Church for responding to this open question in lab)