ROUND= specifier
Standard: F77 F90 F95 F2003 F2008 F2018 Example program
<Syntax>
ROUND = expression
The expression must be a scalar character expression of default kind. It is permitted in the INQUIRE, OPEN, READ and WRITE statements. In the INQUIRE statement, it must be a variable designator and is assigned a value.
<Semantics>
The ROUND= specifier determines the default i/o rounding mode (for OPEN), returns the i/o rounding mode (for INQUIRE), or specifies the i/o rounding mode (for READ and WRITE).
The ROUND= specifier is not permitted in an OPEN, READ or WRITE statement that refers to an unformatted file.
In an INQUIRE statement, if the connection is formatted, the variable is assigned a value indicating the i/o rounding mode for the connection: 'COMPATIBLE'
, 'DOWN'
, 'NEAREST'
, 'PROCESSOR_DEFINED'
, 'UP'
or 'ZERO'
; if there is no connection, or the connection is unformatted, it is assigned 'UNDEFINED'
.
In the OPEN, READ and WRITE statements it must evaluate to one of the previously listed values (except 'UNDEFINED'
), ignoring case.
An input/output rounding mode of 'PROCESSOR_DEFINED'
is not the same as any of the other rounding modes, but its effects are otherwise undefined.
The effects of the other rounding modes are as follows:
-
ROUND='COMPATIBLE'
: round to nearest, with halves away from zero; -
ROUND='DOWN'
: round towards −∞; -
ROUND='NEAREST'
: round to nearest, with halves to even (like IEEE arithmetic); -
ROUND='UP'
: round towards +∞; -
ROUND='ZERO'
: round towards zero.
These effects are illustrated by the following table; output is with an F4.1 edit descriptor.
Internal Value | ROUND='COMPATIBLE' | ROUND='DOWN' | ROUND='NEAREST' | ROUND='UP' | ROUND='ZERO' |
1.25 | 1.3 | 1.2 | 1.2 | 1.3 | 1.2 |
1.75 | 1.8 | 1.7 | 1.8 | 1.8 | 1.7 |
−1.25 | -1.3 | -1.3 | -1.2 | -1.2 | -1.2 |
−1.75 | -1.8 | -1.8 | -1.8 | -1.7 | -1.7 |
<Related>
FORMAT statement, INQUIRE statement, OPEN statement, WRITE statement