9.205 NEAREST — Nearest representable number
- Description:
-
NEAREST(X, S)
returns the processor-representable number nearest toX
in the direction indicated by the sign ofS
. - Standard:
-
Fortran 90 and later
- Class:
-
Elemental function
- Syntax:
-
RESULT = NEAREST(X, S)
- Arguments:
-
X Shall be of type REAL
.S Shall be of type REAL
and not equal to zero. - Return value:
-
The return value is of the same type as
X
. IfS
is positive,NEAREST
returns the processor-representable number greater thanX
and nearest to it. IfS
is negative,NEAREST
returns the processor-representable number smaller thanX
and nearest to it. - Example:
-
program test_nearest real :: x, y x = nearest(42.0, 1.0) y = nearest(42.0, -1.0) write (*,"(3(G20.15))") x, y, x - y end program test_nearest
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/NEAREST.html