Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 83d0df8

Browse files
committedMar 22, 2021
implemented generic clip function in stdlib_math.fypp file
1 parent b522bbb commit 83d0df8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 

‎src/stdlib_math.fypp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#:include "common.fypp"
2+
3+
#:set INT_KINDS_TYPES = [('int8', 'integer'), (int16, 'integer'), ('int32', 'integer'), (int64, 'integer')]
4+
#:set REAL_KINDS_TYPES = [('sp', 'real'), ('dp', 'real'), ('qp', 'real')]
5+
6+
#:set IR_KINDS_TYPES = INT_KINDS_TYPES + REAL_KINDS_TYPES
7+
module stdlib_math
8+
use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp
9+
10+
implicit none
11+
private
12+
public :: clip
13+
14+
15+
interface clip
16+
#:for k1, t1 in IR_KINDS_TYPES
17+
#:set RName = rname('clip', t1, k1)
18+
module function ${RName}$(x, xmin, xmax) result(res)
19+
${t1}$(${k1}$), intent(in) :: x
20+
${t1}$(${k1}$), intent(in) :: xmin
21+
${t1}$(${k1}$), intent(in) :: xmax
22+
${t1}$(${k1}$) :: res
23+
end function ${RName}$
24+
#:endfor
25+
end interface clip
26+
27+
28+
contains
29+
#:for k1, t1 in IR_KINDS_TYPES
30+
#:set RName = rname('clip', t1, k1)
31+
elemental function ${RName}$(x, xmin, xmax) result(res)
32+
res = max(min(x, xmax), xmin)
33+
end function ${RName}$
34+
#:endfor
35+
36+
end module stdlib_math

0 commit comments

Comments
 (0)
Please sign in to comment.