Restricts x to the interval [min_val, max_val].
Values outside the range are replaced by the nearest bound.
Examples
suppressWarnings(clamp(1.5, 0, 1))
#> [1] 1
suppressWarnings(clamp(-0.5, 0, 1))
#> [1] 0
clamp(0.3, 0, 1)
#> [1] 0.3
suppressWarnings(clamp(c(-1, 0.5, 2), 0, 1))
#> [1] 0.0 0.5 1.0
