HP-UX Floating-Point Guide

88 Chapter 3
Factors that Affect the Results of Floating-Point Computations
Floating-Point Coding Practices that Affect Application Results
Figure 3-1 Taking the Difference of Similar Values
The modulo operation (mod(x, y) in Fortran) is an instance of this type
of problem when x is much greater than y; remember that the modulo
formula is
mod(x,y) = x - int(x/y) * y
(See “The Remainder Operation” on page 66 for details.) Trigonometric
and transcendental functions use an enhanced version of mod(x, pi/2)
during argument reduction. Therefore, although HP-UX math libraries
perform extremely careful and accurate argument reduction,
trigonometric functions like cos(x) can lose significance when x is large.
Adding Values with Very Different
Magnitudes
When the system adds two floating-point values, it equalizes the
operands’ exponents before performing the calculation. It does so by
right-shifting the smaller value so as to give it the same exponent as the
larger. If the two values are very different in magnitude, this right shift
causes a major loss of precision in the smaller value, as Figure 3-2
illustrates.