-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.go
34 lines (29 loc) · 585 Bytes
/
util.go
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
// Copyright 2013 Fredrik Ehnbom
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package text
// Returns the minimum of the arguments
func Min(a, b int) int {
if a < b {
return a
}
return b
}
// Returns the maximum of the arguments
func Max(a, b int) int {
if a > b {
return a
}
return b
}
// Clamps v to be in the range of _min and _max
func Clamp(_min, _max, v int) int {
return Max(_min, Min(_max, v))
}
// Returns the absolute value of a.
func Abs(a int) int {
if a < 0 {
return -a
}
return a
}