Generate and return an array of size two containing the minimum and maximum of the two input values in the first and second elements, respectively.
More...
Generate and return an array of size two containing the minimum and maximum of the two input values in the first and second elements, respectively.
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] | a | : The input scalar of the same type and kind as the output minMax .
(optional, it must be present if and only if the input argument b is also present.) |
[in] | b | : The input scalar of the same type and kind as the output minMax .
(optional, it must be present if and only if the input argument a is also present.) |
[in] | pair | : The input vector of length 2 of the same type and kind as the output minMax .
(optional, it must be present if and only if the input arguments a and b are missing.) |
- Returns
minMax
: The output vector of shape (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).
containing min(a,b)
or minval(pair)
in the first element and max(a,b)
or maxval(pair)
in the second element.
Possible calling interfaces ⛓
!
Generate and return an array of size two containing the minimum and maximum of the two input values i...
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.
- Note
- The procedures under this generic interface are particularly useful in combination with getLogAddExp and similar interfaces.
- See also
- setMinMax
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_
"""" )
41 call disp%show(
"Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]")
42 Pair_SK
= [
character(
max(
len(a_SK),
len(b_SK)), SK) :: a_SK, b_SK]
44 call disp%show( Pair_SK , deliml
= SK_
"""" )
45 call disp%show(
"getMinMax(Pair_SK(1), Pair_SK(2))")
50 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
51 call disp%show(
"!Get the min/max of integer values")
52 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
56 call disp%show(
"Pair_IK = [a_IK, b_IK]")
57 Pair_IK
= [a_IK, b_IK]
65 call disp%show(
"Pair_IK = [a_IK, b_IK]")
66 Pair_IK
= [a_IK, b_IK]
69 call disp%show(
"getMinMax(Pair_IK(1), Pair_IK(2))")
74 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
75 call disp%show(
"!Get the min/max of logical values")
76 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
80 call disp%show(
"Pair_LK = [a_LK, b_LK]")
81 Pair_LK
= [a_LK, b_LK]
89 call disp%show(
"Pair_LK = [a_LK, b_LK]")
90 Pair_LK
= [a_LK, b_LK]
93 call disp%show(
"getMinMax(Pair_LK(1), Pair_LK(2))")
98 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
99 call disp%show(
"!Get the min/max of complex values")
100 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
104 call disp%show(
"Pair_CK = [a_CK, b_CK]")
105 Pair_CK
= [a_CK, b_CK]
108 call disp%show(
"getMinMax(Pair_CK)")
113 call disp%show(
"Pair_CK = [a_CK, b_CK]")
114 Pair_CK
= [a_CK, b_CK]
117 call disp%show(
"getMinMax(Pair_CK(1), Pair_CK(2))")
122 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
123 call disp%show(
"!Get the min/max of real values")
124 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
128 call disp%show(
"Pair_RK = [a_RK, b_RK]")
129 Pair_RK
= [a_RK, b_RK]
132 call disp%show(
"getMinMax(Pair_RK)")
137 call disp%show(
"Pair_RK = [a_RK, b_RK]")
138 Pair_RK
= [a_RK, b_RK]
141 call disp%show(
"getMinMax(Pair_RK(1), Pair_RK(2))")
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]
14Pair_SK
= [
character(
max(
len(a_SK),
len(b_SK)), SK) :: a_SK, b_SK]
66(
+10.000000000000000,
-5.0000000000000000), (
+5.0000000000000000,
+15.000000000000000)
68(
+5.0000000000000000,
+15.000000000000000), (
+10.000000000000000,
-5.0000000000000000)
73(
+10.000000000000000,
-5.0000000000000000), (
+5.0000000000000000,
+15.000000000000000)
75(
+5.0000000000000000,
+15.000000000000000), (
+10.000000000000000,
-5.0000000000000000)
85+10.000000000000000,
+5.0000000000000000
87+5.0000000000000000,
+10.000000000000000
92+10.000000000000000,
+5.0000000000000000
94+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 117 of file pm_mathMinMax.F90.