-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.go
60 lines (54 loc) · 857 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
59
60
package main
import (
"math"
"os"
)
func fileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}
func toFixed(num *float64, precision int) {
output := math.Pow(10, float64(precision))
*num = float64(round(*num * output)) / output
}
func byteToInt(b []byte) (c uint, ok bool) {
l := len(b)
if l == 0 {
return
}
var v uint
for i := 0; i < l; i++ {
if b[i] < 48 || b[i] > 57 {
return
}
v = uint(b[i] - '0')
c *= 10
c += v
}
ok = true
return
}
func byteToInt2(b []byte) (c int, ok bool) {
l := len(b)
if l == 0 {
return
}
var v int
for i := 0; i < l; i++ {
if b[i] < 48 || b[i] > 57 {
return
}
v = int(b[i] - '0')
c *= 10
c += v
}
ok = true
return
}