Added assertion to clamp (#17248)

Co-authored-by: flywind <xzsflywind@gmail.com>
This commit is contained in:
Jason Beetham 2021-03-04 18:27:02 -07:00 • committed by GitHub
commit f28dc2c61e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -251,9 +251,12 @@ proc max*[T](x: openArray[T]): T =
proc clamp*[T](x, a, b: T): T =
## Limits the value `x` within the interval [a, b].
## This proc is equivalent to but fatser than `max(a, min(b, x))`.
## This proc is equivalent to but faster than `max(a, min(b, x))`.
##
## **Note:** `a <= b` is assumed and will not be checked.
## .. warning:: `a <= b` is assumed and will not be checked (currently).
##
## **See also:**
## `math.clamp` for a version that takes a `Slice[T]` instead.
runnableExamples:
assert (1.4).clamp(0.0, 1.0) == 1.0
assert (0.5).clamp(0.0, 1.0) == 0.5