Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [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 | |
girishk | e7ca43b | 2019-10-10 12:30:03 +0000 | [diff] [blame^] | 19 | // IntMax returns the maximum of the params |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 20 | func IntMax(a, b int) int { |
| 21 | if b > a { |
| 22 | return b |
| 23 | } |
| 24 | return a |
| 25 | } |
| 26 | |
girishk | e7ca43b | 2019-10-10 12:30:03 +0000 | [diff] [blame^] | 27 | // IntMin returns the minimum of the params |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 28 | func IntMin(a, b int) int { |
| 29 | if b < a { |
| 30 | return b |
| 31 | } |
| 32 | return a |
| 33 | } |
| 34 | |
girishk | e7ca43b | 2019-10-10 12:30:03 +0000 | [diff] [blame^] | 35 | // Int32Max returns the maximum of the params |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 36 | func Int32Max(a, b int32) int32 { |
| 37 | if b > a { |
| 38 | return b |
| 39 | } |
| 40 | return a |
| 41 | } |
| 42 | |
girishk | e7ca43b | 2019-10-10 12:30:03 +0000 | [diff] [blame^] | 43 | // Int32Min returns the minimum of the params |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 44 | func Int32Min(a, b int32) int32 { |
| 45 | if b < a { |
| 46 | return b |
| 47 | } |
| 48 | return a |
| 49 | } |
| 50 | |
girishk | e7ca43b | 2019-10-10 12:30:03 +0000 | [diff] [blame^] | 51 | // Int64Max returns the maximum of the params |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 52 | func Int64Max(a, b int64) int64 { |
| 53 | if b > a { |
| 54 | return b |
| 55 | } |
| 56 | return a |
| 57 | } |
| 58 | |
girishk | e7ca43b | 2019-10-10 12:30:03 +0000 | [diff] [blame^] | 59 | // Int64Min returns the minimum of the params |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 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 | } |