ROUND

Category

Floating-point and integer control

Pragma equivalent

None.

Purpose

Specifies the rounding mode for the compiler to use when evaluating constant floating-point expressions at compile time.

Syntax

The syntax depends on whether the ROUND option is used with a base 2 IEEE-754 binary format (specified by the FLOAT(IEEE) compiler option), base 16 z/Architecture® hexadecimal format (specified by the FLOAT(HEX) compiler option), or base 10 decimal floating-point format (specified by the DFP compiler option).

When FLOAT(IEEE) is specified:

Read syntax diagramSkip visual syntax diagram
             .-N-.      
>>-ROUND--(--+-M-+--)------------------------------------------><
             +-P-+      
             '-Z-'      

When FLOAT(HEX) is specified:

Read syntax diagramSkip visual syntax diagram
>>-ROUND--(--Z--)----------------------------------------------><

When DFP is specified:

Read syntax diagramSkip visual syntax diagram
             .-DN--.      
>>-ROUND--(--+-DI--+--)----------------------------------------><
             +-DM--+      
             +-DNA-+      
             +-DNZ-+      
             +-DP--+      
             '-DZ--'      

Defaults

Parameters

The rounding mode depends on whether the ROUND option is used with the DFP compiler option.

If FLOAT(IEEE) is in effect but DFP is not in effect, the following modes are valid:

N
round to the nearest representable number (ties to even)
Note: A tie occurs when the number to be rounded is at the exact midpoint between two values towards which it can be rounded. For example, if we are rounding to the nearest representable whole number, and we are given the value 1.5, we are at the exact midpoint between the two nearest whole numbers (2 and 1). This is considered a tie. In this example, and using ties to even, we would round the value 1.5 to the value 2, as 2 is an even number.
M
round towards minus infinity
P
round towards positive infinity
Z
round towards zero
Note: ROUND() is the same as ROUND(N).

If the DFP compiler option is in effect, the following modes are valid:

DI
round towards infinity (away from zero)
DM
round towards minus infinity
DN
round to the nearest representable number (ties to even)
DNA
round to the nearest representable number (ties away from zero)
Note: The value will round to the nearest representable number, but when there is a tie, it will round towards the larger magnitude (or away from zero).
DNZ
round to the nearest representable number (ties towards zero)
Note: The value will round to the nearest representable number, but when there is a tie, it will round towards the smaller magnitude (or towards zero).
DP
round towards positive infinity
DZ
round towards zero

Usage

You can specify a rounding mode only when you use IEEE floating-point mode. In hexadecimal mode, the rounding is always towards zero.

You must ensure that you are in the same rounding mode at compile time (specified by the ROUND(mode) option), as at run time. Entire compilation units will be compiled with the same rounding mode throughout the compilation. For further information on the DFP header files and functions, see z/OS XL C/C++ Runtime Library Reference. If you switch runtime rounding modes inside a function, your results may vary depending upon the optimization level used and other characteristics of your code; use caution if you switch rounding mode inside functions.

If you specify ROUND(mode) in hexadecimal floating-point mode, where mode is not Z, the compiler ignores ROUND(mode) and issues a warning.

IPA effects

The IPA compile step generates information for the IPA link step. The ROUND option also affects the regular object module if you request one by specifying the IPA(OBJECT) option.

The IPA link step merges and optimizes the application code, and then divides it into sections for code generation. Each of these section is a partition. The IPA link step uses information from the IPA compile step to ensure that an object is included in a compatible partition. Refer to the FLOAT for further information.

Predefined macros

None.

Related information

For information about related compiler options, see: