Matteo Scandolo | a428586 | 2020-12-01 18:10:10 -0800 | [diff] [blame^] | 1 | /* |
| 2 | Copyright 2019 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 value |
| 18 | |
| 19 | // Compare compares floats. The result will be 0 if lhs==rhs, -1 if f < |
| 20 | // rhs, and +1 if f > rhs. |
| 21 | func 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. |
| 32 | func 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. |
| 43 | func 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 | } |