MCPcopy Create free account
hub / github.com/brimdata/super / CompareFloat64

Function CompareFloat64

runtime/sam/expr/boolean.go:139–168  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
139func 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
170var compareString = map[string]func(string, string) bool{
171 "==": func(a, b string) bool { return a == b },

Callers 1

ComparisonFunction · 0.85

Calls 10

NewBoolFunction · 0.92
compareFunction · 0.85
UnderMethod · 0.80
IsNullMethod · 0.80
IsErrorMethod · 0.80
FloatMethod · 0.80
IDMethod · 0.65
TypeMethod · 0.65
UintMethod · 0.45
IntMethod · 0.45

Tested by

no test coverage detected