Clamp/Limit the value of x
to the range of [xmin
, xmax
], where x
, xmin
, and xmax
are all integers.
No check is performed to ensure xmin
< xmax
.
(KCW, 2025-07-16)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int64), | intent(in) | :: | x | |||
integer(kind=int64), | intent(in) | :: | xmin | |||
integer(kind=int64), | intent(in) | :: | xmax |
pure elemental function clamp_int64(x, xmin, xmax) result(clamp) use, intrinsic :: iso_fortran_env, only: int64 integer(int64), intent(in) :: x, xmin, xmax integer(int64) :: clamp clamp = max(min(x, xmax), xmin) end function clamp_int64