summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflaviut <tamasflaviu@gmail.com>2014-04-08 18:00:44 -0400
committerflaviut <tamasflaviu@gmail.com>2014-04-08 18:00:44 -0400
commitfde53bffd7ea707f70028ec42aa2d7cd225d4293 (patch)
tree76fb9f046a913eb599c700582a2fe92e4423e619
parent2a470c4217e0ee7d002afd7910e875e4079edc08 (diff)
downloadNim-fde53bffd7ea707f70028ec42aa2d7cd225d4293.tar.gz
Code example for `clamp`
-rw-r--r--lib/system.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 6de9f3a8a..f5b1c3fe5 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1507,7 +1507,11 @@ proc max*(x, y: float): float {.magic: "MaxF64", noSideEffect.} =
 {.pop.}
 
 proc clamp*[T](x, a, b: T): T =
-  ## limits the value ``x`` within the interval [a, b] 
+  ## limits the value ``x`` within the interval [a, b]
+  ##
+  ## .. code-block:: Nimrod
+  ##   assert((1.4).clamp(0.0, 1.0) == 1.0)
+  ##   assert((0.5).clamp(0.0, 1.0) == 0.5)
   if x < a: return a
   if x > b: return b
   return x
ef='/ahoang/Nim/commit/compiler/gorgeimpl.nim?h=devel&id=02ff5f596c330b68927f843814ecb9b86c2eee67'>02ff5f596 ^
fedc13698 ^
02ff5f596 ^




























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58