vitess.io/vitess@v0.16.2/go/vt/vtorc/util/math.go (about)

     1  /*
     2     Copyright 2014 Shlomi Noach.
     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 util
    18  
    19  func MinInt(i1, i2 int) int {
    20  	if i1 < i2 {
    21  		return i1
    22  	}
    23  	return i2
    24  }
    25  
    26  func MaxInt(i1, i2 int) int {
    27  	if i1 > i2 {
    28  		return i1
    29  	}
    30  	return i2
    31  }
    32  
    33  func MinInt64(i1, i2 int64) int64 {
    34  	if i1 < i2 {
    35  		return i1
    36  	}
    37  	return i2
    38  }
    39  
    40  func MaxInt64(i1, i2 int64) int64 {
    41  	if i1 > i2 {
    42  		return i1
    43  	}
    44  	return i2
    45  }
    46  
    47  func MaxUInt64(i1, i2 uint64) uint64 {
    48  	if i1 > i2 {
    49  		return i1
    50  	}
    51  	return i2
    52  }
    53  
    54  func MinString(i1, i2 string) string {
    55  	if i1 < i2 {
    56  		return i1
    57  	}
    58  	return i2
    59  }
    60  
    61  // TernaryString acts like a "? :" C-style ternary operator for strings
    62  func TernaryString(condition bool, resTrue string, resFalse string) string {
    63  	if condition {
    64  		return resTrue
    65  	}
    66  	return resFalse
    67  }
    68  
    69  // TernaryInt acts like a "? :" C-style ternary operator for ints
    70  func TernaryInt(condition bool, resTrue int, resFalse int) int {
    71  	if condition {
    72  		return resTrue
    73  	}
    74  	return resFalse
    75  }
    76  
    77  // AbsInt64 is an ABS function for int64 type
    78  func AbsInt64(i int64) int64 {
    79  	if i >= 0 {
    80  		return i
    81  	}
    82  	return -i
    83  }