Return a predicate for comparing this value to one more typed byte slices by calling the predicate function with a Value. Operand is one of "==", "!=", "<", "<=", ">", ">=".
(op string, pattern int64)
| 70 | // byte slices by calling the predicate function with a Value. |
| 71 | // Operand is one of "==", "!=", "<", "<=", ">", ">=". |
| 72 | func CompareInt64(op string, pattern int64) (Boolean, error) { |
| 73 | CompareInt, ok1 := compareInt[op] |
| 74 | CompareFloat, ok2 := compareFloat[op] |
| 75 | if !ok1 || !ok2 { |
| 76 | return nil, fmt.Errorf("unknown int comparator: %s", op) |
| 77 | } |
| 78 | // many different data types can be compared with integers |
| 79 | return func(val super.Value) super.Value { |
| 80 | val = val.Under() |
| 81 | if val.IsNull() { |
| 82 | return super.Null |
| 83 | } |
| 84 | if val.IsError() { |
| 85 | return val |
| 86 | } |
| 87 | switch val.Type().ID() { |
| 88 | case super.IDUint8, super.IDUint16, super.IDUint32, super.IDUint64: |
| 89 | if v := val.Uint(); v <= math.MaxInt64 { |
| 90 | return super.NewBool(CompareInt(int64(v), pattern)) |
| 91 | } |
| 92 | case super.IDInt8, super.IDInt16, super.IDInt32, super.IDInt64, super.IDTime, super.IDDuration: |
| 93 | return super.NewBool(CompareInt(val.Int(), pattern)) |
| 94 | case super.IDFloat16, super.IDFloat32, super.IDFloat64: |
| 95 | return super.NewBool(CompareFloat(val.Float(), float64(pattern))) |
| 96 | } |
| 97 | return super.False |
| 98 | }, nil |
| 99 | } |
| 100 | |
| 101 | // XXX should just do equality and we should compare in the encoded domain |
| 102 | // and not make copies and have separate cases for len 4 and len 16 |