CompareFloat64 returns a Predicate that compares typed byte slices that must be coercible to an double with the value's double value using a comparison based on op. Int, count, port, and double types can all be converted to the integer value. XXX there are some overflow issues here.
(op string, pattern float64)
| 137 | // based on op. Int, count, port, and double types can |
| 138 | // all be converted to the integer value. XXX there are some overflow issues here. |
| 139 | func CompareFloat64(op string, pattern float64) (Boolean, error) { |
| 140 | compare, ok := compareFloat[op] |
| 141 | if !ok { |
| 142 | return nil, fmt.Errorf("unknown double comparator: %s", op) |
| 143 | } |
| 144 | return func(val super.Value) super.Value { |
| 145 | val = val.Under() |
| 146 | if val.IsNull() { |
| 147 | return super.Null |
| 148 | } |
| 149 | if val.IsError() { |
| 150 | return val |
| 151 | } |
| 152 | switch val.Type().ID() { |
| 153 | // We allow comparison of float constant with integer-y |
| 154 | // fields and just use typeDouble to parse since it will do |
| 155 | // the right thing for integers. XXX do we want to allow |
| 156 | // integers that cause float64 overflow? user can always |
| 157 | // use an integer constant instead of a float constant to |
| 158 | // compare with the integer-y field. |
| 159 | case super.IDUint8, super.IDUint16, super.IDUint32, super.IDUint64: |
| 160 | return super.NewBool(compare(float64(val.Uint()), pattern)) |
| 161 | case super.IDInt8, super.IDInt16, super.IDInt32, super.IDInt64, super.IDTime, super.IDDuration: |
| 162 | return super.NewBool(compare(float64(val.Int()), pattern)) |
| 163 | case super.IDFloat16, super.IDFloat32, super.IDFloat64: |
| 164 | return super.NewBool(compare(val.Float(), pattern)) |
| 165 | } |
| 166 | return super.False |
| 167 | }, nil |
| 168 | } |
| 169 | |
| 170 | var compareString = map[string]func(string, string) bool{ |
| 171 | "==": func(a, b string) bool { return a == b }, |