...

Source file src/k8s.io/utils/integer/integer.go

Documentation: k8s.io/utils/integer

     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  import "math"
    20  
    21  // IntMax returns the maximum of the params
    22  func IntMax(a, b int) int {
    23  	if b > a {
    24  		return b
    25  	}
    26  	return a
    27  }
    28  
    29  // IntMin returns the minimum of the params
    30  func IntMin(a, b int) int {
    31  	if b < a {
    32  		return b
    33  	}
    34  	return a
    35  }
    36  
    37  // Int32Max returns the maximum of the params
    38  func Int32Max(a, b int32) int32 {
    39  	if b > a {
    40  		return b
    41  	}
    42  	return a
    43  }
    44  
    45  // Int32Min returns the minimum of the params
    46  func Int32Min(a, b int32) int32 {
    47  	if b < a {
    48  		return b
    49  	}
    50  	return a
    51  }
    52  
    53  // Int64Max returns the maximum of the params
    54  func Int64Max(a, b int64) int64 {
    55  	if b > a {
    56  		return b
    57  	}
    58  	return a
    59  }
    60  
    61  // Int64Min returns the minimum of the params
    62  func Int64Min(a, b int64) int64 {
    63  	if b < a {
    64  		return b
    65  	}
    66  	return a
    67  }
    68  
    69  // RoundToInt32 rounds floats into integer numbers.
    70  // Deprecated: use math.Round() and a cast directly.
    71  func RoundToInt32(a float64) int32 {
    72  	return int32(math.Round(a))
    73  }
    74  

View as plain text