LF Fortran 95

ANINT Function

Description

The ANINT function rounds a REAL number up or down to the nearest whole number.

Syntax

ANINT (a [, kind])

Required Arguments

a is an INTENT(IN) scalar or array of type REAL.

Optional Arguments

kind is INTENT(IN) and determines the kind of the result. It must be a scalar INTEGER expression that can be evaluated at compile time. To maintain portability, this argument should be the result of a KIND Function or SELECTED_REAL_KIND Function.

Result

The result is a type REAL number representing the whole number nearest to the argument. If a > 0, the result has the value INT(a + 0.5); if a ≤ 0, the result has the value INT(a - 0.5).

If kind is present, the result is the same kind as kind.

If kind is absent, the result is the same kind as a.

Example

real :: x=7.73,y=1.5,z=-1.5 write(*,*) anint(x,kind(1.d0)) ! writes 8.000000000000000 write(*,*) anint(y) ! writes 2.0000000 write(*,*) anint(z) ! writes -2.0000000

See Also

KIND Function

SELECTED_REAL_KIND Function