HP-UX Floating-Point Guide
78 Chapter 3
Factors that Affect the Results of Floating-Point Computations
Other System-Related Factors that Affect Application Results
The Fortran program displays results similar to the following:
Y = .3304651080717299
Y = 3FD526571FE8C7A5
The following C program shows how you can use a union to display
floating-point values in hexadecimal:
Sample Program: flophex.c
#include <stdio.h>
#include <math.h>
union {
double y;
struct {
unsigned int ym, yl;
} i;
} di;
int main(void)
{
double x;
x = 1.234e0;
di.y = cos(x);
printf("di.y = %18.16g\n", di.y);
printf("di.y = %08x%08x\n", di.i.ym, di.i.yl);
}
The C program displays results similar to the following:
di.y = 0.3304651080717299
di.y = 3fd526571fe8c7a5
Compiler Behavior and Compiler Version
The compiler can contribute to variations in floating-point results in
several ways, including
• Conversion of constants
• Decisions about constant folding and algorithms used in constant
folding
• Rearrangement of operations
Like the math library functions, the parsing routines (both the run-time
routines such as READ and scanf and the internal routines the compiler
uses) attempt to come as close as possible to the ideal accuracy of less
than 1/2 ULP and to be bit-for-bit compatible from one release to another.
However, these routines may change slightly from time to time. Because