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