HP-UX Floating-Point Guide
94 Chapter 3
Factors that Affect the Results of Floating-Point Computations
Floating-Point Coding Practices that Affect Application Results
Ill-Conditioned Computations
If relatively small changes to the input of a program or to the
intermediate results generated by a program cause relatively large
changes in the final output, the program is said to be ill-conditioned or
numerically unstable.
The following example illustrates an ill-conditioned program:
Sample Program: sloppy_tangent.f
C The following program is an example of how small
C perturbations in the argument to a function near the
C function’s singularity can cause large variations in the
C function’s result. A program may be ill-conditioned because
C of a case like this, where minor inaccuracies created during
C preliminary calculations become major inaccuracies when they
C are passed through a function at a point where the function
C has a very steep slope.
PROGRAM SLOPPY_TANGENT
DOUBLE PRECISION X
X = 1.570796D0
WRITE(*,*) 'TAN( X-1.0D-5 ):', TAN( X-1.0D-5 )
WRITE(*,*) 'TAN( X ): ', TAN( X )
WRITE(*,*) 'TAN( X+1.0D-5 ):', TAN( X+1.0D-5 )
END
The output from this program shows how small changes in the argument
to the TAN function lead to wildly varying results:
TAN( X-1.0D-5 ): 96835.46637430933
TAN( X ): 3060023.306952844
TAN( X+1.0D-5 ): -103378.351773411
Ill-conditioned computations cause trouble not because their input
values may change, but because the seemingly innocuous rounding
errors and loss of significance can have large effects on the final results.
One way to establish that rounding errors and loss of significance are
causing a program to produce incorrect results is to run the program in
various rounding modes. (See “Rounding Mode: fegetround and
fesetround” on page 130 for information on how to change rounding
modes using the fesetround function.) However, this technique does
not always work. In the preceding example, for instance, changing the
rounding mode has little effect on the results. However, if you do observe
that simply changing the rounding mode causes large changes in the
application results, then your application is most likely ill-conditioned.