Add IntRange.ContainsNonNegative

This commit is contained in:
Nigel Tao committed 2019-11-02 11:59:22 +11:00
1 parent 29c7b67874
commit 8ce3d657ee
1 file changed
+13 -1
+13 -1
View File
@@ -241,6 +241,18 @@ func (x IntRange) ContainsNegative() bool {
return x[1] == nil || x[0].Cmp(x[1]) <= 0
}
// ContainsNonNegative returns whether x contains at least one non-negative
// value.
func (x IntRange) ContainsNonNegative() bool {
if x[1] == nil {
return true
}
if x[1].Sign() < 0 {
return false
}
return x[0] == nil || x[0].Cmp(x[1]) <= 0
}
// ContainsPositive returns whether x contains at least one positive value.
func (x IntRange) ContainsPositive() bool {
if x[1] == nil {
@@ -818,7 +830,7 @@ func andBothNonNeg(x IntRange, y IntRange) (z IntRange) {
}
func andOneNegOneNonNeg(neg IntRange, non IntRange) (z IntRange) {
if neg.Empty() || neg.ContainsZero() || neg.ContainsPositive() || non.Empty() || non.ContainsNegative() {
if neg.Empty() || neg.ContainsNonNegative() || non.Empty() || non.ContainsNegative() {
panic("pre-condition failure")
}