Skip to content

Commit 9136fe5

Browse files
committed
implemented generic clip function and modified CMakeLists.txt & Makefile.manual files
1 parent b522bbb commit 9136fe5

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(fppFiles
2222
stdlib_quadrature_trapz.fypp
2323
stdlib_quadrature_simps.fypp
2424
stdlib_stats_distribution_PRNG.fypp
25+
stdlib_math.fypp
2526
)
2627

2728

src/Makefile.manual

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ SRCFYPP =\
1818
stdlib_stats_moment_mask.fypp \
1919
stdlib_stats_moment_scalar.fypp \
2020
stdlib_stats_var.fypp \
21+
stdlib_math.fypp \
2122
stdlib_stats_distribution_PRNG.fypp
2223

2324
SRC = f18estop.f90 \

src/stdlib_math.fypp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
module function clip_${t1}$_${k1}$(x, xmin, xmax) result(res)
18+
${t1}$(${k1}$), intent(in) :: x
19+
${t1}$(${k1}$), intent(in) :: xmin
20+
${t1}$(${k1}$), intent(in) :: xmax
21+
${t1}$(${k1}$) :: res
22+
end function clip_${t1}$_${k1}$
23+
#:endfor
24+
end interface clip
25+
26+
27+
contains
28+
#:for k1, t1 in IR_KINDS_TYPES
29+
elemental function clip_${t1}$_${k1}$(x, xmin, xmax) result(res)
30+
res = max(min(x, xmax), xmin)
31+
end function clip_${t1}$_${k1}$
32+
#:endfor
33+
34+
end module stdlib_math

0 commit comments

Comments
 (0)