diff options
author | Jason Beetham <beefers331@gmail.com> | 2021-03-03 16:54:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-03 23:54:23 +0000 |
commit | c180de60a8ac5459d1e553152132fcfc6cd2fe6f (patch) | |
tree | b11fc11ab418a191fc39a844d893a618c301b638 /tests | |
parent | f561afae419212e6eeb33f37f834aa7e9d4b9d6f (diff) | |
download | Nim-c180de60a8ac5459d1e553152132fcfc6cd2fe6f.tar.gz |
Added math.clamp for slice clamping (#17246)
* Added math.clamp for slice clamping * Added inline to math.clamp * Cleaned up math.clamp + test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdlib/tmath.nim | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/stdlib/tmath.nim b/tests/stdlib/tmath.nim index 350ee59e9..49b4c82f1 100644 --- a/tests/stdlib/tmath.nim +++ b/tests/stdlib/tmath.nim @@ -358,6 +358,17 @@ template main() = doAssert almostEqual(prod([1.5, 3.4]), 5.1) let x: seq[float] = @[] doAssert prod(x) == 1.0 + + block: # clamp range + doAssert clamp(10, 1..5) == 5 + doAssert clamp(3, 1..5) == 3 + doAssert clamp(5, 1..5) == 5 + doAssert clamp(42.0, 1.0 .. 3.1415926535) == 3.1415926535 + doAssert clamp(NaN, 1.0 .. 2.0).isNaN + doAssert clamp(-Inf, -Inf .. -1.0) == -Inf + type A = enum a0, a1, a2, a3, a4, a5 + doAssert a1.clamp(a2..a4) == a2 + doAssert clamp((3, 0), (1, 0) .. (2, 9)) == (2, 9) when not defined(windows): # xxx pending bug #17017 doAssert sqrt(-1.0).isNaN |