NEAREST — Nearest representable number#
- 
NEAREST(X, S)#
- NEAREST(X, S)returns the processor-representable number nearest to- Xin the direction indicated by the sign of- S.- Parameters:
- X – Shall be of type - REAL.
- S – Shall be of type - REALand not equal to zero.
 
- Returns:
- The return value is of the same type as - X. If- Sis positive,- NEARESTreturns the processor-representable number greater than- Xand nearest to it. If- Sis negative,- NEARESTreturns the processor-representable number smaller than- Xand nearest to it.
 - Standard:
- Fortran 90 and later 
- Class:
- Elemental function 
- Syntax:
- RESULT = NEAREST(X, S) 
- 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