blob: c78a4c18d122bccc813040ddaee0ff6acd8e3c2c [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
2Copyright 2019 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package value
18
19// Compare compares floats. The result will be 0 if lhs==rhs, -1 if f <
20// rhs, and +1 if f > rhs.
21func FloatCompare(lhs, rhs float64) int {
22 if lhs > rhs {
23 return 1
24 } else if lhs < rhs {
25 return -1
26 }
27 return 0
28}
29
30// IntCompare compares integers. The result will be 0 if i==rhs, -1 if i <
31// rhs, and +1 if i > rhs.
32func IntCompare(lhs, rhs int64) int {
33 if lhs > rhs {
34 return 1
35 } else if lhs < rhs {
36 return -1
37 }
38 return 0
39}
40
41// Compare compares booleans. The result will be 0 if b==rhs, -1 if b <
42// rhs, and +1 if b > rhs.
43func BoolCompare(lhs, rhs bool) int {
44 if lhs == rhs {
45 return 0
46 } else if lhs == false {
47 return -1
48 }
49 return 1
50}