Matteo Scandolo | a428586 | 2020-12-01 18:10:10 -0800 | [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 | // IntMax returns the maximum of the params |
| 20 | func 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 |
| 28 | func 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 |
| 36 | func 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 |
| 44 | func 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 |
| 52 | func 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 |
| 60 | func 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. |
| 68 | func RoundToInt32(a float64) int32 { |
| 69 | if a < 0 { |
| 70 | return int32(a - 0.5) |
| 71 | } |
| 72 | return int32(a + 0.5) |
| 73 | } |