C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

There are conditions defined in these standards that could not occur in the HP implementation on
older systems. These conditions include an argument or return value of NaN (not-a-number) and
positive and negative infinity. Because these conditions could not occur, the Tandem floating-point
format variants of the mathematical functions do not take actions defined in the standards.
For example, the XPG4 cos() function definition requires that NaN be returned if the parameter
to the function is NaN. The definition further states that errno optionally might be set to [EDOM].
Because the Tandem floating-point format does not support NaN, the cos() function does not
return NaN or optionally set errno to [EDOM]. Note that if you specify IEEE floating-point format,
NaN is supported.
The standards specify the action that must or might occur for a given condition. If the condition
cannot occur in a given implementation, the action is not required. Therefore, the HP C run-time
libraries conform to the standards. Many of the reference pages for the mathematical functions
state the actions defined by the standards, even if the conditions that require those actions cannot
occur in the HP implementation. These actions are included to enable you to write code that has
the highest level of portability to other environments.
IEEE Floating-Point Arithmetic
You have the option of choosing Tandem floating-point format or IEEE floating-point format for
performing floating-point arithmetic in native C and C++ programs. Tandem floating-point format
is the default for TNS/R systems; IEEE floating-point format is the default for TNS/E systems.
Tandem floating-point format is compatible with pre-G06.06 C and C++ applications. IEEE
floating-point format, however, allows an application to take advantage of the greater performance
provided by the floating-point instructions available in the processor hardware. Note that the results
of IEEE floating-point operations can vary slightly between TNS/R and TNS/E systems.
Differences Between Tandem and IEEE Floating-Point Formats
These are some high-level differences between the two floating-point formats:
IEEE floating-point format covers a wider range of values for the double data type, but a
narrower range of values for the float data type, than does Tandem floating-point format
(see Table 11: Comparison of IEEE and Tandem Floating-Point Formats ).
IEEE floating-point format has greater precision than Tandem floating-point format.for the
float data type, but slightly less precision for a double.
IEEE floating-point format is faster than Tandem floating-point format.
IEEE floating-point format is easier for porting applications.
IEEE floating-point default handling of overflow, underflow, divide-by-zero, and invalid operation
is better than the Tandem floating-point handling.
IEEE floating-point directed roundings and “sticky” flags are useful debugging tools for
investigating calculations that might go wrong because of rounding problems, division by
zero, or other problems. Sticky flags are exception flags that stay set until explicitly reset by
the user. They allow you to check a chain of computations.
IEEE floating-point denormalized numbers avoid computational problems that arise from very
small numbers as intermediate results in computations.
IEEE floating-point format is available only on NonStop servers with the underlying hardware
capacity, running a G06.06 or later version of the HP NonStop OS.
For more general information about IEEE floating-point format, see Compiling and Linking
Floating-Point Programs (page 301), and see the Guardian Programmer’s Guide. For more details
about using IEEE floating-point format (including the exponent ranges and the number of bits of
exponents and fractions), see the pragma IEEE_FLOAT (page 203).
Table 11 lists the differences in precision between the two floating-point formats.
Mathematical Functions 75