SPACING(3) - [MODEL_COMPONENTS] Smallest distance between two numbers of a given type
result = spacing(x)
elemental real(kind=KIND) function spacing(x)real(kind=KIND), intent(in) :: x
o X is type real of any valid kind o The result is of the same type as the input argument X.
SPACING(3) determines the distance between the argument X and the nearest adjacent number of the same type.
o X : Shall be of type real.
If X does not have the value zero and is not an IEEE infinity or NaN, the result has the value nearest to X for values of the same type and kind assuming the value is representable.
Otherwise, the value is the same as TINY(X). + zero produces TINY(X) + IEEE Infinity produces an IEEE Nan + if an IEEE NaN, that NaN is returned
If there are two extended model values equally near to X, the value of greater absolute value is taken.
Sample program:
program demo_spacing implicit none integer, parameter :: sgl = selected_real_kind(p=6, r=37) integer, parameter :: dbl = selected_real_kind(p=13, r=200)Results:write(*,*) spacing(1.0_sgl) write(*,*) nearest(1.0_sgl,+1.0),nearest(1.0_sgl,+1.0)-1.0
write(*,*) spacing(1.0_dbl) end program demo_spacing
Typical values ...
> 1.1920929E-07 > 1.000000 1.1920929E-07 > 0.9999999 -5.9604645E-08 > 2.220446049250313E-016
Fortran 95
DIGITS(3), EPSILON(3), EXPONENT(3), FRACTION(3), HUGE(3), MAXEXPONENT(3), MINEXPONENT(3), NEAREST(3), PRECISION(3), RADIX(3), RANGE(3), RRSPACING(3), SCALE(3), SET_EXPONENT(3), TINY(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | spacing (3fortran) | November 02, 2024 |