Return the minimum and maximum of the two input scalar values a
and b
in a
and b
, respectively, on output.
Note that strings and complex values are compared lexicographically. See pm_complexCompareLex and pm_container for more information on the relevant lexical comparison operators.
Also, note that a logical .false.
is less than .true.
in this module.
- Parameters
-
[in,out] | a | : The input/output scalar, or array of the same rank, shape, and size other array-like arguments, of either
-
type
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary len type-parameter, or
-
type
integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or
-
type
logical of kind any supported by the processor (e.g., LK) or
-
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).
On output, its value will be overwritten with min(a,b) .
(optional, it must be present if and only if the argument b is also present.) |
[in,out] | b | : The input/output scalar, or array of the same rank, shape, and size other array-like arguments, of the same type and kind as the input a .
On output, its value will be overwritten with max(a,b) .
(optional, it must be present if and only if the argument a is also present.) |
[in,out] | pair | : The input/output vector of size 2 of either,
-
type
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary len type-parameter, or
-
type
integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or
-
type
logical of kind any supported by the processor (e.g., LK) or
-
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).
On output, its value will be overwritten with [min(a,b), max(a,b)] .
(optional, it must be present if and only if the arguments a and b are missing.) |
Possible calling interfaces ⛓
!
Return the minimum and maximum of the two input scalar values a and b in a and b, respectively,...
This module contains procedures and generic interfaces for finding the minimum and maximum of two inp...
- Warning
- If the two input arguments
a
and b
are of type character
, then they are assumed to have the same length.
Otherwise, the output minMax
will have a length type parameter that is the maximum of the two input values.
This means that array padding with blanks will occur for the value of the shorter string.
For clarifications, see the examples below.
-
The rank and size of the two input arguments must be the same.
- Note
- The procedures under this generic interface are particularly useful in combination with getLogAddExp and similar interfaces.
- See also
- getMinMax
getLogAddExp
Example usage ⛓
9 type(display_type) :: disp
11 character(:, SK),
allocatable :: a_SK, b_SK, Pair_SK(:)
12 integer(IK) :: a_IK, b_IK, Pair_IK(
2)
13 logical(LK) :: a_LK, b_LK, Pair_LK(
2)
14 complex(CK) :: a_CK, b_CK, Pair_CK(
2)
15 real(RK) :: a_RK, b_RK, Pair_RK(
2)
17 a_SK
= "Hell" ; b_SK
= "Heaven"
18 a_IK
= 10_IK ; b_IK
= 5_IK
19 a_LK
= .true._LK ; b_LK
= .false._LK
20 a_CK
= (
+10._CK,
-5._CK); b_CK
= (
+5._CK,
+15._CK)
21 a_RK
= 10._RK ; b_RK
= 5._RK
26 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show(
"!Get the min/max of string values")
28 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
32 call disp%show(
"Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]")
33 Pair_SK
= [
character(
max(
len(a_SK),
len(b_SK)), SK) :: a_SK, b_SK]
35 call disp%show( Pair_SK , deliml
= SK_
"""" )
36 call disp%show(
"call setMinMax(Pair_SK)")
39 call disp%show( Pair_SK , deliml
= SK_
"""" )
43 call disp%show(
"Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]")
44 Pair_SK
= [
character(
max(
len(a_SK),
len(b_SK)), SK) :: a_SK, b_SK]
46 call disp%show( Pair_SK , deliml
= SK_
"""" )
47 call disp%show(
"call setMinMax(Pair_SK(1), Pair_SK(2))")
50 call disp%show( Pair_SK , deliml
= SK_
"""" )
54 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
55 call disp%show(
"!Get the min/max of integer values")
56 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
60 call disp%show(
"Pair_IK = [a_IK, b_IK]")
61 Pair_IK
= [a_IK, b_IK]
64 call disp%show(
"call setMinMax(Pair_IK)")
71 call disp%show(
"Pair_IK = [a_IK, b_IK]")
72 Pair_IK
= [a_IK, b_IK]
75 call disp%show(
"call setMinMax(Pair_IK(1), Pair_IK(2))")
82 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
83 call disp%show(
"!Get the min/max of logical values")
84 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
88 call disp%show(
"Pair_LK = [a_LK, b_LK]")
89 Pair_LK
= [a_LK, b_LK]
92 call disp%show(
"call setMinMax(Pair_LK)")
99 call disp%show(
"Pair_LK = [a_LK, b_LK]")
100 Pair_LK
= [a_LK, b_LK]
103 call disp%show(
"call setMinMax(Pair_LK(1), Pair_LK(2))")
110 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
111 call disp%show(
"!Get the min/max of complex values")
112 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
116 call disp%show(
"Pair_CK = [a_CK, b_CK]")
117 Pair_CK
= [a_CK, b_CK]
120 call disp%show(
"call setMinMax(Pair_CK)")
127 call disp%show(
"Pair_CK = [a_CK, b_CK]")
128 Pair_CK
= [a_CK, b_CK]
131 call disp%show(
"call setMinMax(Pair_CK(1), Pair_CK(2))")
138 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
139 call disp%show(
"!Get the min/max of real values")
140 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
144 call disp%show(
"Pair_RK = [a_RK, b_RK]")
145 Pair_RK
= [a_RK, b_RK]
148 call disp%show(
"call setMinMax(Pair_RK)")
155 call disp%show(
"Pair_RK = [a_RK, b_RK]")
156 Pair_RK
= [a_RK, b_RK]
159 call disp%show(
"call setMinMax(Pair_RK(1), Pair_RK(2))")
166 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
167 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
168 call disp%show(
"!Elemental min/max setting")
169 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
170 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
174 integer(IK),
allocatable :: a(:), b(:)
182 call disp%show(
"call setMinMax(a, b)")
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 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.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
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 ⛓
7Pair_SK
= [
character(
max(
len(a_SK),
len(b_SK)), SK) :: a_SK, b_SK]
15Pair_SK
= [
character(
max(
len(a_SK),
len(b_SK)), SK) :: a_SK, b_SK]
72(
+10.000000000000000,
-5.0000000000000000), (
+5.0000000000000000,
+15.000000000000000)
75(
+5.0000000000000000,
+15.000000000000000), (
+10.000000000000000,
-5.0000000000000000)
80(
+10.000000000000000,
-5.0000000000000000), (
+5.0000000000000000,
+15.000000000000000)
83(
+5.0000000000000000,
+15.000000000000000), (
+10.000000000000000,
-5.0000000000000000)
93+10.000000000000000,
+5.0000000000000000
96+5.0000000000000000,
+10.000000000000000
101+10.000000000000000,
+5.0000000000000000
104+5.0000000000000000,
+10.000000000000000
- Test:
- test_pm_mathMinMax
- Todo:
- Low Priority: This generic interface can be expanded to include the possibility of passing user-defined custom comparison.
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:
- Amir Shahmoradi, Thursday 1:45 AM, August 22, 2019, Dallas, TX
Definition at line 789 of file pm_mathMinMax.F90.