Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

NINT

Elemental Intrinsic Function (Generic): Returns the nearest integer to the argument.

result = NINT (a[,kind])

a

(Input) Must be of type real.

kind

(Input; optional) Must be a scalar integer constant expression.

Results

The result type is integer. If kind is present, the kind parameter of the result is that specified by kind; otherwise, the kind parameter of the result is shown in the following table. If the processor cannot represent the result value in the kind of the result, the result is undefined.

If a is greater than zero, NINT(a) has the value INT(a+ 0.5); if a is less than or equal to zero, NINT(a) has the value INT(a- 0.5).

Specific Name

Argument Type

Result Type

ININT

REAL(4)

INTEGER(2)

NINT 1, 2

REAL(4)

INTEGER(4)

KNINT

REAL(4)

INTEGER(8)

IIDNNT

REAL(8)

INTEGER(2)

IDNINT 2, 3

REAL(8)

INTEGER(4)

KIDNNT

REAL(8)

INTEGER(8)

IIQNNT

REAL(16)

INTEGER(2)

IQNINT2, 4

REAL(16)

INTEGER(4)

KIQNNT

REAL(16)

INTEGER(8)

1Or JNINT.

2The setting of compiler options specifying integer size can affect NINT, IDNINT, and IQNINT.

3Or JIDNNT. For compatibility with older versions of Fortran, IDNINT can also be specified as a generic function.

4Or JIQNNT. For compatibility with older versions of Fortran, IQNINT can also be specified as a generic function.

Example

NINT (3.879) has the value 4.

NINT (-2.789) has the value -3.

The following shows another example:

 INTEGER(4) i1, i2
 i1 = NINT(2.783) ! returns 3
 i2 = IDNINT(-2.783D0) ! returns -3

See Also