Manual Reference Pages  - nearest (3fortran)

NAME

NEAREST(3) - [MODEL:COMPONENTS] Nearest representable number

SYNOPSIS

result = nearest(x, s)

         elemental real(kind=KIND) function nearest(x,s)

real(kind=KIND),intent(in) :: x real(kind=**),intent(in) :: s

CHARACTERISTICS

o X may be a real value of any kind.
o S may be a real value of any kind.
o The return value is of the same type and kind as X.
o a kind designated as ** may be any supported kind for the type

DESCRIPTION

NEAREST(3) returns the processor-representable number nearest to X in the direction indicated by the sign of S.

OPTIONS

o X : the value to find the nearest representable value of
o S : a non-zero value whose sign is used to determine the direction in which to search from X to the representable value.

If S is positive, NEAREST returns the processor-representable number greater than X and nearest to it.

If S is negative, NEAREST returns the processor-representable number smaller than X and nearest to it.

RESULT

The return value is of the same type as X. If S is positive, NEAREST returns the processor-representable number greater than X and nearest to it. If S is negative, NEAREST returns the processor-representable number smaller than X and nearest to it.

EXAMPLES

Sample program:

    program demo_nearest
    implicit none

real :: x, y x = nearest(42.0, 1.0) y = nearest(42.0, -1.0) write (*,"(3(g20.15))") x, y, x - y

! write (*,"(3(g20.15))") & ! nearest(tiny(0.0),1.0), & ! nearest(tiny(0.0),-1.0), & ! nearest(tiny(0.0),1.0) -nearest(tiny(0.0),-1.0)

! write (*,"(3(g20.15))") & ! nearest(huge(0.0),1.0), & ! nearest(huge(0.0),-1.0), & ! nearest(huge(0.0),1.0)- nearest(huge(0.0),-1.0)

end program demo_nearest

Results:

      > 42.0000038146973    41.9999961853027    .762939453125000E-05

STANDARD

Fortran 95

SEE ALSO

DIGITS(3), EPSILON(3), EXPONENT(3), FRACTION(3), HUGE(3), MAXEXPONENT(3), MINEXPONENT(3), PRECISION(3), RADIX(3), RANGE(3), RRSPACING(3), SCALE(3), SET_EXPONENT(3), SPACING(3), TINY(3)

Fortran intrinsic descriptions


Nemo Release 3.1 nearest (3fortran) November 02, 2024
Generated by manServer 1.08 from 650ea30c-49f4-4446-8621-dffb7a39b95e using man macros.