HP-UX Floating-Point Guide
Chapter 3 73
Factors that Affect the Results of Floating-Point Computations
How Mathematical Library Functions Affect Application Results
How Mathematical Library Functions
Affect Application Results
Mathematical library functions do not always yield identical results from
one system to another, from one language to another, or even from one
software release to another. The reason is that computer vendors often
modify these functions for any or all of the following purposes:
• To make them faster
• To make them more accurate
• To take advantage of the capabilities of a particular hardware system
The art in algorithm design for math library routines is in finding the
best tradeoff between accuracy and performance. Some algorithms are
better than others at getting the most accurate results obtainable. For a
given function, it is usually possible to design an algorithm that produces
results that are accurate to within the 1/2 ULP mandated for the results
of the basic operations. The most precise algorithm, however, is often
unacceptably slow. Because correct rounding is not required for most
mathematical functions (though it is required for basic operations and
for some functions, such as sqrt), algorithm designers are free to
sacrifice a small amount of accuracy in favor of better performance. As
advances in algorithm design improve the speed and/or accuracy of the
library functions, the results may change.
Because HP modifies math functions from time to time, you should not
count on always getting identical results from a given function. Instead,
it is wise to assume that a library call may have an error of 1 ULP or
thereabouts. As we explain in “Testing Floating-Point Values for
Equality” on page 84, you should test for results within a certain range,
not for an exact value.