HP-UX Floating-Point Guide
Chapter 3 77
Factors that Affect the Results of Floating-Point Computations
Other System-Related Factors that Affect Application Results
The conversion between a decimal value and a binary floating-point
value may cause a loss of accuracy for any of three reasons:
• The algorithm may not be accurate, probably because speed/accuracy
tradeoffs have been made in favor of speed.
• Not all decimal values are exactly representable in binary—for
example, 0.1.
• The conversion may be specified so as to deliberately limit precision.
For example, the statements
REAL X
READ (*, '(G5.2)') X
deliver only three decimal digits of precision (5 minus 1 for the sign
and 1 for the decimal point). If the user enters −1.23456, the last
three digits are lost. The same loss of precision on output can be
particularly confusing if it causes very small values to be printed as
zero, as in the following example:
REAL X
X = 1.0E-10
WRITE(*, '(F5.2)') X
Displaying Floating-Point Values in Binary
It is possible in each language to read or print floating-point variables
directly in binary (actually hexadecimal), where no conversion
inaccuracies occur. Floating-point programmers should familiarize
themselves with these techniques and should also examine floating-point
variables in hexadecimal in the symbolic debugger.
The following Fortran program shows how you can display floating-point
values in hexadecimal:
Sample Program: flophex.f
PROGRAM FLOPHEX
DOUBLE PRECISION X, Y
X = 1.234D0
Y = DCOS(X)
WRITE(*, 5) Y
WRITE(*, 10) Y
5 FORMAT(‘ Y = ‘, F18.16)
10 FORMAT(‘ Y = ‘, Z16.16)
END