32 PUBLIC ::
OPERATOR (.equalto.)
33 PUBLIC ::
OPERATOR (.greaterthan.)
34 PUBLIC ::
OPERATOR (.lessthan.)
52 INTERFACE OPERATOR (.equalto.)
57 END INTERFACE OPERATOR (.EqualTo.)
59 INTERFACE OPERATOR (.greaterthan.)
62 END INTERFACE OPERATOR (.GreaterThan.)
64 INTERFACE OPERATOR (.lessthan.)
67 END INTERFACE OPERATOR (.LessThan.)
88 '$Id: Compare_Float_Numbers.f90 60152 2015-08-13 19:19:13Z paul.vandelst@noaa.gov $' 90 REAL(Single),
PARAMETER ::
sp_zero = 0.0_single
91 REAL(Double),
PARAMETER ::
dp_zero = 0.0_double
92 REAL(Single),
PARAMETER ::
sp_one = 1.0_single
93 REAL(Double),
PARAMETER ::
dp_one = 1.0_double
94 REAL(Single),
PARAMETER ::
sp_ten = 10.0_single
95 REAL(Double),
PARAMETER ::
dp_ten = 10.0_double
145 REAL(Single),
INTENT(IN) :: x, y
147 equalto = abs(x-y) < spacing(
max(abs(x),abs(y)) )
151 REAL(Double),
INTENT(IN) :: x, y
153 equalto = abs(x-y) < spacing(
max(abs(x),abs(y)) )
157 COMPLEX(Single),
INTENT(IN) :: x, y
159 REAL(Single) :: rx, ix
160 REAL(Single) :: ry, iy
161 rx =
REAL(x,
single); ix = aimag(x)
162 ry =
REAL(y,
single); iy = aimag(y)
167 COMPLEX(Double),
INTENT(IN) :: x, y
169 REAL(Double) :: rx, ix
170 REAL(Double) :: ry, iy
171 rx =
REAL(x,
double); ix = aimag(x)
172 ry =
REAL(y,
double); iy = aimag(y)
217 REAL(Single),
INTENT(IN) :: x, y
218 LOGICAL :: greater_than
219 IF ( (x-y) >= spacing(
max( abs(x), abs(y) ) ) )
THEN 220 greater_than = .true.
222 greater_than = .false.
228 REAL(Double),
INTENT(IN) :: x, y
229 LOGICAL :: greater_than
230 IF ( (x-y) >= spacing(
max( abs(x), abs(y) ) ) )
THEN 231 greater_than = .true.
233 greater_than = .false.
278 REAL(Single),
INTENT(IN) :: x, y
280 IF ( (y-x) >= spacing(
max( abs(x), abs(y) ) ) )
THEN 289 REAL(Double),
INTENT(IN) :: x, y
291 IF ( (y-x) >= spacing(
max( abs(x), abs(y) ) ) )
THEN 402 REAL(Single),
INTENT(IN) :: x
403 REAL(Single),
INTENT(IN) :: y
404 INTEGER ,
OPTIONAL,
INTENT(IN) :: ulp
405 REAL(Single),
OPTIONAL,
INTENT(IN) :: percent
415 IF (
PRESENT(ulp) )
THEN 416 rel =
REAL(ABS(ULP),
single)
420 IF (
PRESENT(percent) )
THEN 423 IF ( abs(x) < ( spacing(
max(abs(x),
sp_zero) ) ) ) ulp_test = .true.
429 compare = abs(x-y) < ( rel * spacing(
max(abs(x),abs(y)) ) )
438 REAL(Double),
INTENT(IN) :: x
439 REAL(Double),
INTENT(IN) :: y
440 INTEGER ,
OPTIONAL,
INTENT(IN) :: ulp
441 REAL(Double),
OPTIONAL,
INTENT(IN) :: percent
451 IF (
PRESENT(ulp) )
THEN 452 rel =
REAL(ABS(ULP),
double)
456 IF (
PRESENT(percent) )
THEN 459 IF ( abs(x) < ( spacing(
max(abs(x),
dp_zero) ) ) ) ulp_test = .true.
465 compare = abs(x-y) < ( rel * spacing(
max(abs(x),abs(y)) ) )
474 COMPLEX(Single),
INTENT(IN) :: x
475 COMPLEX(Single),
INTENT(IN) :: y
476 INTEGER ,
OPTIONAL,
INTENT(IN) :: ulp
477 REAL(Single) ,
OPTIONAL,
INTENT(IN) :: percent
481 REAL(Single) :: xr, xi
482 REAL(Single) :: yr, yi
486 xr=
REAL(x,
single); xi=aimag(x)
487 yr=
REAL(y,
single); yi=aimag(y)
498 COMPLEX(Double),
INTENT(IN) :: x
499 COMPLEX(Double),
INTENT(IN) :: y
500 INTEGER ,
OPTIONAL,
INTENT(IN) :: ulp
501 REAL(Double) ,
OPTIONAL,
INTENT(IN) :: percent
505 REAL(Double) :: xr, xi
506 REAL(Double) :: yr, yi
510 xr=
REAL(x,
double); xi=aimag(x)
511 yr=
REAL(y,
double); yi=aimag(y)
562 REAL(Single),
INTENT(IN) :: x
563 INTEGER ,
INTENT(IN) :: n
567 e = floor(log10(abs(x))) - n
575 REAL(Double),
INTENT(IN) :: x
576 INTEGER,
INTENT(IN) :: n
580 e = floor(log10(abs(x))) - n
588 COMPLEX(Single),
INTENT(IN) :: x
589 INTEGER,
INTENT(IN) :: n
591 REAL(Single) :: tr, ti
598 COMPLEX(Double),
INTENT(IN) :: x
599 INTEGER,
INTENT(IN) :: n
601 REAL(Double) :: tr, ti
664 REAL(Single),
INTENT(IN) :: x, y
665 INTEGER,
INTENT(IN) :: n
666 REAL(Single),
OPTIONAL,
INTENT(IN) :: cutoff
667 LOGICAL :: is_comparable
669 IF (
PRESENT(cutoff) )
THEN 674 is_comparable = .true.
675 IF ( abs(x) > c .OR. abs(y) > c ) is_comparable = abs(x-y) <
tolerance(x,n)
680 REAL(Double),
INTENT(IN) :: x, y
681 INTEGER,
INTENT(IN) :: n
682 REAL(Double),
OPTIONAL,
INTENT(IN) :: cutoff
683 LOGICAL :: is_comparable
685 IF (
PRESENT(cutoff) )
THEN 690 is_comparable = .true.
691 IF ( abs(x) > c .OR. abs(y) > c ) is_comparable = abs(x-y) <
tolerance(x,n)
696 COMPLEX(Single),
INTENT(IN) :: x, y
697 INTEGER,
INTENT(IN) :: n
698 COMPLEX(Single),
OPTIONAL,
INTENT(IN) :: cutoff
699 LOGICAL :: is_comparable
701 IF (
PRESENT(cutoff) )
THEN 712 COMPLEX(Double),
INTENT(IN) :: x, y
713 INTEGER,
INTENT(IN) :: n
714 COMPLEX(Double),
OPTIONAL,
INTENT(IN) :: cutoff
715 LOGICAL :: is_comparable
717 IF (
PRESENT(cutoff) )
THEN elemental logical function cwt_complex_double(x, y, n, cutoff)
real(single), parameter sp_ten
elemental complex(single) function tolerance_complex_single(x, n)
elemental logical function compare_real_double(x, y, ULP, Percent)
elemental logical function is_greater_than_double(x, y)
real(double), parameter dp_compare_cutoff
elemental logical function equalto_real_double(x, y)
elemental logical function compare_complex_single(x, y, ULP, Percent)
integer, parameter, public double
integer, parameter, public single
elemental logical function compare_complex_double(x, y, ULP, Percent)
elemental logical function is_less_than_double(x, y)
elemental logical function is_greater_than_single(x, y)
real(double), parameter dp_zero
real(double), parameter dp_one
real(double), parameter dp_ten
elemental logical function is_less_than_single(x, y)
elemental real(double) function tolerance_real_double(x, n)
elemental logical function equalto_real_single(x, y)
character(*), parameter module_version_id
integer, parameter, public default_n_sigfig
elemental logical function cwt_real_single(x, y, n, cutoff)
real(single), parameter sp_compare_cutoff
elemental complex(double) function tolerance_complex_double(x, n)
elemental logical function compare_real_single(x, y, ULP, Percent)
elemental logical function cwt_complex_single(x, y, n, cutoff)
real(single), parameter sp_hundred
real(single), parameter sp_zero
elemental logical function equalto_complex_double(x, y)
real(single), parameter sp_one
real(double), parameter dp_hundred
elemental logical function cwt_real_double(x, y, n, cutoff)
elemental logical function equalto_complex_single(x, y)
elemental real(single) function tolerance_real_single(x, n)