ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_mathCompare::isClose Interface Reference

Generate and return .true. if the two input values are sufficiently close to each other within the specified tolerances.
More...

Detailed Description

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

use pm_kind, only: LK
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...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
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.
Remarks
The procedures under discussion are elemental.
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

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_kind, only: RKS, RKD, RKH ! all processor types and kinds are supported.
5 use pm_kind, only: CKS, CKD, CKH ! all processor types and kinds are supported.
6 use pm_io, only: display_type
7 use pm_except, only: getInfNeg
8 use pm_except, only: getInfPos
9 use pm_except, only: getNAN
10 use pm_mathCompare, only: isClose
12
13 implicit none
14
15 type(display_type) :: disp
16 disp = display_type(file = "main.out.F90")
17
18 call disp%skip
19 call disp%show("isClose(0., [0., tiny(0.), epsilon(0.), 1.])")
20 call disp%show( isClose(0., [0., tiny(0.), epsilon(0.), 1.]) )
21 call disp%skip
22
23 call disp%skip
24 call disp%show("isClose(0., [0., tiny(0.), epsilon(0.), 1.], MEAN)")
25 call disp%show( isClose(0., [0., tiny(0.), epsilon(0.), 1.], MEAN) )
26 call disp%skip
27
28 call disp%skip
29 call disp%show("isClose(0., [0., tiny(0.), epsilon(0.), 1.], WEAK)")
30 call disp%show( isClose(0., [0., tiny(0.), epsilon(0.), 1.], WEAK) )
31 call disp%skip
32
33 call disp%skip
34 call disp%show("isClose(0., [0., tiny(0.), epsilon(0.), 1.], STRONG)")
35 call disp%show( isClose(0., [0., tiny(0.), epsilon(0.), 1.], STRONG) )
36 call disp%skip
37
38 call disp%skip
39 call disp%show("isClose(0., [0., tiny(0.), epsilon(0.), 1.], REFERENCE)")
40 call disp%show( isClose(0., [0., tiny(0.), epsilon(0.), 1.], REFERENCE) )
41 call disp%skip
42
43 call disp%skip
44 call disp%show("isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.])")
45 call disp%show( isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.]) )
46 call disp%skip
47
48 call disp%skip
49 call disp%show("isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], MEAN)")
50 call disp%show( isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], MEAN) )
51 call disp%skip
52
53 call disp%skip
54 call disp%show("isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], WEAK)")
55 call disp%show( isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], WEAK) )
56 call disp%skip
57
58 call disp%skip
59 call disp%show("isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], STRONG)")
60 call disp%show( isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], STRONG) )
61 call disp%skip
62
63 call disp%skip
64 call disp%show("isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], REFERENCE)")
65 call disp%show( isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], REFERENCE) )
66 call disp%skip
67
68 call disp%skip
69 call disp%show("isClose(getInfNeg(mold = 0.), [1., getInfNeg(0.), getInfPos(0.), getNAN(0.)])")
70 call disp%show( isClose(getInfNeg(mold = 0.), [1., getInfNeg(0.), getInfPos(0.), getNAN(0.)]) )
71 call disp%skip
72
73 call disp%skip
74 call disp%show("isClose(getNAN(0.), getNAN(0.))")
75 call disp%show( isClose(getNAN(0.), getNAN(0.)) )
76 call disp%skip
77
78 call disp%skip
79 call disp%show("isClose((0., 0.), cmplx(tiny(0.), tiny(0.)))")
80 call disp%show( isClose((0., 0.), cmplx(tiny(0.), tiny(0.))) )
81 call disp%skip
82
83 call disp%skip
84 call disp%show("isClose((0., 0.), cmplx(epsilon(0.), epsilon(0.)))")
85 call disp%show( isClose((0., 0.), cmplx(epsilon(0.), epsilon(0.))) )
86 call disp%skip
87
88 call disp%skip
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.)) )
91 call disp%skip
92
93 call disp%skip
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.)) )
96 call disp%skip
97
98end program example
Generate and return an IEEE-compliant negative infinity.
Definition: pm_except.F90:1719
Generate and return an IEEE-compliant positive infinity.
Definition: pm_except.F90:1189
Generate and return an IEEE-compliant quiet NAN (Not a Number).
Definition: pm_except.F90:2414
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains procedures and generic interfaces for testing for exceptional cases at runtime.
Definition: pm_except.F90:46
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
integer, parameter CKH
The scalar integer constant of intrinsic default kind, representing the highest-precision complex kin...
Definition: pm_kind.F90:843
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
Definition: pm_kind.F90:570
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter CKD
The double precision complex kind in Fortran mode. On most platforms, this is a 64-bit real kind.
Definition: pm_kind.F90:571
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
Definition: pm_kind.F90:568
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
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.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2isClose(0., [0., tiny(0.), epsilon(0.), 1.])
3T, T, F, F
4
5
6isClose(0., [0., tiny(0.), epsilon(0.), 1.], MEAN)
7T, T, F, F
8
9
10isClose(0., [0., tiny(0.), epsilon(0.), 1.], WEAK)
11T, T, F, F
12
13
14isClose(0., [0., tiny(0.), epsilon(0.), 1.], STRONG)
15T, T, F, F
16
17
18isClose(0., [0., tiny(0.), epsilon(0.), 1.], REFERENCE)
19T, T, F, F
20
21
22isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.])
23T, T, T, F
24
25
26isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], MEAN)
27T, T, T, F
28
29
30isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], WEAK)
31T, T, T, F
32
33
34isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], STRONG)
35T, T, T, F
36
37
38isClose(1., 1. + [0., tiny(0.), epsilon(0.), 1.], REFERENCE)
39T, T, T, F
40
41
42isClose(getInfNeg(mold = 0.), [1., getInfNeg(0.), getInfPos(0.), getNAN(0.)])
43F, T, F, F
44
45
46isClose(getNAN(0.), getNAN(0.))
47F
48
49
50isClose((0., 0.), cmplx(tiny(0.), tiny(0.)))
51F
52
53
54isClose((0., 0.), cmplx(epsilon(0.), epsilon(0.)))
55F
56
57
58isClose((1., 1.), (1., 1.) + cmplx(epsilon(0.), epsilon(0.)), reltol = 2 * epsilon(0.))
59T
60
61
62isClose((0., 0.), cmplx(tiny(0.), tiny(0.)), abstol = 2 * tiny(0.))
63T
64
65
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.

  1. 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.
  2. 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.

Author:
Fatemeh Bagheri, Tuesday 08:49 PM, August 10, 2021, Dallas, TX

Definition at line 535 of file pm_mathCompare.F90.


The documentation for this interface was generated from the following file: