blob: e4e740cad4c8223ad58e19ec580985d8cfbc2969 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package integer
18
19// IntMax returns the maximum of the params
20func IntMax(a, b int) int {
21 if b > a {
22 return b
23 }
24 return a
25}
26
27// IntMin returns the minimum of the params
28func IntMin(a, b int) int {
29 if b < a {
30 return b
31 }
32 return a
33}
34
35// Int32Max returns the maximum of the params
36func Int32Max(a, b int32) int32 {
37 if b > a {
38 return b
39 }
40 return a
41}
42
43// Int32Min returns the minimum of the params
44func Int32Min(a, b int32) int32 {
45 if b < a {
46 return b
47 }
48 return a
49}
50
51// Int64Max returns the maximum of the params
52func Int64Max(a, b int64) int64 {
53 if b > a {
54 return b
55 }
56 return a
57}
58
59// Int64Min returns the minimum of the params
60func Int64Min(a, b int64) int64 {
61 if b < a {
62 return b
63 }
64 return a
65}
66
67// RoundToInt32 rounds floats into integer numbers.
68func RoundToInt32(a float64) int32 {
69 if a < 0 {
70 return int32(a - 0.5)
71 }
72 return int32(a + 0.5)
73}