When in doubt, use brute force.
--- Ken Thompson, Bell Labs
One of the advantages of multiple-precision is that the difficulties presented by problems that
are ill-conditioned or algorithms that are unstable can often be overcome by raising precision.
If we need a result correct to 15 digits and there is a simple algorithm that loses 10 digits to
cancellation error, it may be easier to write a program to use FM and carry 30 digits, instead of
spending the time to develop a sophisticated algorithm that can get 15 digits using double precision.
William Kahan is a numerical analysis guru whose web page http://www.cs.berkeley.edu/~wkahan/
has many papers showing in grisly detail some of the terrible things that can happen to the unwary
people who design or use numerical software.
In one of Kahan's articles, "How Futile are Mindless Assessments of Roundoff in Floating-Point
Computation?", he says,
"How can you separate numerically trustworthy results from the treacherous ones?"
"Without error-analysis, you can't. And if you can't, the simplest way to evade numerical
embarrassment is to perform computation carrying extravagantly more precision throughout
than you think necessary, and pray that it is enough. Usually somewhat more than twice the
precision you trust in the data and seek in the results is enough."
FM can make it relatively painless to check numerical results by re-running them with
Some of the .chk output files contain timing results. The times may vary when you run the programs.
The routines on this page are mostly brute force solutions and not state-of-the-art methods.
They all use the basic FM package, and should be compiled and linked in a similar way to the
other Fortran sample programs discussed in the FM user manual.
The actual files shown on this page are in this archive that contains all the FM files from this
The individual file pointers here display as pdf files for browsing. The longer files are cut
off after 20 pages.
Sample Routines Collected in One File
is a file that collects all the subroutines on this page into one file.
This is usually more convenient when using these routines, since only one object file is needed
when building programs that use them.
See the top of this file for a list of the routines.
Using FM for Special Functions
Some programs don't need multiple precision, but do need mathematical special functions
that are not part of the Fortran standard. In this case it is easy to set FM's precision level
to give full double precision accuracy and then use FM's version of these functions.
is a small program with several examples using FM for non-Fortran
functions such as binomial coefficients, log integral, psi, polygamma, and incomplete gamma.
is the expected output from the program. Note that the first example
checks Fortran's built-in gamma function against FM. At the time this routine was created,
some Fortran compilers did not give correctly rounded results for all valid input arguments
to gamma, so your output might differ from this file in the first sample case.
Function Minimization or Maximization
is a program that includes FM_FIND_MIN, a multiple-precision max/min subroutine.
It is discussed on this page about (semi-) automatic conversion to use FM.
fminFMv2.chk is the output from the fminFMv2 program.
contains FM_FPRIME, a multiple-precision subroutine for nth derivatives
of real functions.
contains ZM_FPRIME, a multiple-precision subroutine for nth derivatives
of complex functions.
contains FM_INTEGRATE, a multiple-precision subroutine for definite
integrals of real functions.
SampleFMintegrate.f95 is a sample program using FM_INTEGRATE.
SampleFMintegrate.chk is the output from the SampleFMintegrate program.
OscillateFM.f95 is a program that uses FM_INTEGRATE to integrate sin(1/x) from 0 to 1.
OscillateFM.chk is the output from the OscillateFM program.
Ordinary Differential Equations
contains FM_RK14, a multiple-precision subroutine for ordinary differential
equations (initial value problems).
DiffEqFM.f95 is a sample program using FM_RK14.
DiffEqFM.chk is the output from the DiffEqFM program.
SecantFM.f95 contains FM_SECANT, a multiple-precision root-finding subroutine.
RootsFM.f95 is a sample program using routines in files SecantFM and FprimeFM.
RootsFM.chk is the output from the RootsFM program.
Real Linear Systems
LinSolveFM.f95 contains FM_LIN_SOLVE, a routine for solving systems of linear equations.
InverseFM.f95 contains FM_INVERSE, a routine for finding the inverse of a real matrix.
contains FM_GENEQ, a routine that generates the system of normal equations
for solving a linear least-squares problem.
HarmonicFitFM.f95 is a sample program using routines in files GeneqFM and LinSolveFM.
HarmonicFitFM.chk is the output from the HarmonicFitFM program.
contains ZM_SECANT, a multiple-precision root-finding subroutine
for complex functions.
RootsZM.f95 contains ZM_ROOTS, a subroutine that tries to find many roots for complex functions.
AllRootsZM.f95 is a sample program using routines in file RootsZM.
AllRootsZM.chk is the output from the AllRootsZM program.
Complex Linear Systems and Eigenvalues
contains ZM_LIN_SOLVE, a routine for solving systems of linear equations
having complex coefficients.
InverseZM.f95 contains ZM_INVERSE, a routine for finding the inverse of a complex matrix.
is a sample program that tries to find the complex eigenvalues and eigenvectors
of a real matrix.
It uses routines in files LinSolveFM, RootsZM, FprimeZM, LinSolveZM, and InverseZM.
EigenSystem.chk is the screen output from the EigenSystem program.
EigenSystem.out is the file output from the EigenSystem program.