forked from hzane/enet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
58 lines (52 loc) · 755 Bytes
/
utils.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package enet
import "time"
// unixtime millisecond
func unixtimeNow() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}
func time2i64(t time.Time) int64 {
n := t.UnixNano()
return n / int64(time.Millisecond)
}
func time2ui32(t time.Time) uint32 {
return uint32(time2i64(t))
}
func betweenui32(a, r, l uint32) uint32 {
if a > l {
a = l
}
if a < r {
a = r
}
return a
}
func minui32(a, b uint32) uint32 {
if a < b {
return a
}
return b
}
func absi64(v int64) int64 {
if v > 0 {
return v
}
return -v
}
func mini64(a, b int64) int64 {
if a > b {
return b
}
return a
}
func maxi64(a, b int64) int64 {
if a > b {
return a
}
return b
}
func maxui32(a, b uint32) uint32 {
if a > b {
return b
}
return a
}