Fix precision handling in validating LimitRange

This commit is contained in:
derekwaynecarr
2015-09-08 14:49:54 -04:00
parent 61a66a95a6
commit ea919f6d1e
4 changed files with 182 additions and 175 deletions

View File

@@ -301,6 +301,27 @@ func (q *Quantity) String() string {
return number + string(suffix)
}
// Cmp compares q and y and returns:
//
// -1 if q < y
// 0 if q == y
// +1 if q > y
//
func (q *Quantity) Cmp(y Quantity) int {
num1 := q.Value()
num2 := y.Value()
if num1 < MaxMilliValue && num2 < MaxMilliValue {
num1 = q.MilliValue()
num2 = y.MilliValue()
}
if num1 < num2 {
return -1
} else if num1 > num2 {
return 1
}
return 0
}
func (q *Quantity) Add(y Quantity) error {
if q.Format != y.Format {
return fmt.Errorf("format mismatch: %v vs. %v", q.Format, y.Format)