Generate and return .true.
if the two input values are sufficiently close to each other within the specified tolerances.
See the documentation of pm_mathCompare for extensive details of possible testing modes.
- Parameters
-
[in] | x | : The input scalar, or array of the same rank as other array-like arguments, of,
-
type
complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or,
-
type
real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
whose proximity to the input y will be tested based on the specified method and tolerances.
|
[in] | y | : The input scalar, or array of the same rank as other array-like arguments, of the same type and kind as the input x , whose proximity to the input x will be tested based on the specified method and tolerances.
|
[in] | method | : The input scalar, or array of the same rank as other array-like arguments, of,
whose presence is solely used to determine the scaling of the relative tolerance for the proximity test.
If method = reference_type() , then the input x will be taken as the reference value.
(optional, default = WEAK) |
[in] | reltol | : The input positive scalar, or array of the same rank as other array-like arguments, of type real of the same kind as the input argument x , representing the relative tolerance to be used in the proximity test.
(optional, default = epsilon(x) ) |
[in] | abstol | : The input positive scalar, or array of the same rank as other array-like arguments, of type real of the same kind as the input argument x , representing the absolute tolerance to be used in the proximity test.
(optional, default = tiny(x) ) |
- Returns
close
: The output scalar, or array of the same rank as other array-like arguments, of type logical
of default kind LK.
It is .true.
if and only if the two input values x
and y
is close to each other according to the specified testing method and tolerances.
Possible calling interfaces ⛓
logical(LK) :: close
close = isClose(x, y, reltol
= reltol, abstol
= abstol)
close = isClose(x, y, method, reltol
= reltol, abstol
= abstol)
Generate and return .true. if the two input values are sufficiently close to each other within the sp...
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
This module contains the procedures and interfaces for evaluating the relative or absolute proximity ...
- Warning
- The condition
0. <= abstol
must hold for the corresponding arguments.
The condition 0. <= reltol
must hold for the corresponding arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
-
The
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.
By default, these procedures are pure
in release
build and impure
in debug
and testing
builds.
- Note
- A
-Inf
value is considered not close to a +Inf
in all circumstances.
Two +Inf
values or two -Inf
values are considered close to each other in all circumstances.
A NaN
value is considered not close to any other value including another NaN
in all circumstances.
- See also
- pm_test
Example usage ⛓
15 type(display_type) :: disp
19 call disp%show(
"isClose(0., [0., tiny(0.), epsilon(0.), 1.])")
24 call disp%show(
"isClose(0., [0., tiny(0.), epsilon(0.), 1.], MEAN)")
29 call disp%show(
"isClose(0., [0., tiny(0.), epsilon(0.), 1.], WEAK)")
34 call disp%show(
"isClose(0., [0., tiny(0.), epsilon(0.), 1.], STRONG)")
39 call disp%show(
"isClose(0., [0., tiny(0.), epsilon(0.), 1.], REFERENCE)")
44 call disp%show(
"isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.])")
49 call disp%show(
"isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], MEAN)")
54 call disp%show(
"isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], WEAK)")
59 call disp%show(
"isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], STRONG)")
64 call disp%show(
"isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], REFERENCE)")
69 call disp%show(
"isClose(getInfNeg(mold = 0.), [1., getInfNeg(0.), getInfPos(0.), getNAN(0.)])")
74 call disp%show(
"isClose(getNAN(0.), getNAN(0.))")
79 call disp%show(
"isClose((0., 0.), cmplx(tiny(0.), tiny(0.)))")
84 call disp%show(
"isClose((0., 0.), cmplx(epsilon(0.), epsilon(0.)))")
89 call disp%show(
"isClose((1., 1.), (1., 1.) + cmplx(epsilon(0.), epsilon(0.)), reltol = 2 * epsilon(0.))")
90 call disp%show(
isClose((
1.,
1.), (
1.,
1.)
+ cmplx(
epsilon(
0.),
epsilon(
0.)), reltol
= 2 * epsilon(
0.)) )
94 call disp%show(
"isClose((0., 0.), cmplx(tiny(0.), tiny(0.)), abstol = 2 * tiny(0.))")
95 call disp%show(
isClose((
0.,
0.),
cmplx(
tiny(
0.),
tiny(
0.)), abstol
= 2 * tiny(
0.)) )
Generate and return an IEEE-compliant negative infinity.
Generate and return an IEEE-compliant positive infinity.
Generate and return an IEEE-compliant quiet NAN (Not a Number).
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
This module contains procedures and generic interfaces for testing for exceptional cases at runtime.
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
integer, parameter CKH
The scalar integer constant of intrinsic default kind, representing the highest-precision complex kin...
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter CKD
The double precision complex kind in Fortran mode. On most platforms, this is a 64-bit real kind.
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
type(weak_type), parameter WEAK
This is a convenience constant object of type weak_type() that is exclusively provided to distinguish...
type(strong_type), parameter STRONG
This is a convenience constant object of type strong_type() that is exclusively provided to distingui...
type(reference_type), parameter REFERENCE
This is a convenience constant object of type reference_type() that is exclusively provided to distin...
type(mean_type), parameter MEAN
This is a convenience constant object of type mean_type() that is exclusively provided to distinguish...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
2isClose(
0., [
0.,
tiny(
0.),
epsilon(
0.),
1.])
22isClose(
1.,
1. + [
0.,
tiny(
0.),
epsilon(
0.),
1.])
26isClose(
1.,
1. + [
0.,
tiny(
0.),
epsilon(
0.),
1.],
MEAN)
30isClose(
1.,
1. + [
0.,
tiny(
0.),
epsilon(
0.),
1.],
WEAK)
50isClose((
0.,
0.),
cmplx(
tiny(
0.),
tiny(
0.)))
54isClose((
0.,
0.),
cmplx(
epsilon(
0.),
epsilon(
0.)))
58isClose((
1.,
1.), (
1.,
1.)
+ cmplx(
epsilon(
0.),
epsilon(
0.)), reltol
= 2 * epsilon(
0.))
62isClose((
0.,
0.),
cmplx(
tiny(
0.),
tiny(
0.)), abstol
= 2 * tiny(
0.))
- Test:
- test_pm_mathCompare
- Todo:
- The implementations of the procedures of this generic interface can be improved to ensure robustness against possible rare cases of overflows and underflow as discussed in the documentation of pm_mathCompare.
Final Remarks ⛓
If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.
-
If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
-
If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.
This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.
- Copyright
- Computational Data Science Lab
- Author:
- Fatemeh Bagheri, Tuesday 08:49 PM, August 10, 2021, Dallas, TX
Definition at line 535 of file pm_mathCompare.F90.