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

Method Call

runtime/sam/expr/function/math.go:92–131  ·  view source on GitHub ↗
(args []super.Value)

Source from the content-addressed store, hash-verified

90}
91
92func (r *reducer) Call(args []super.Value) super.Value {
93 val0 := args[0]
94 switch id := val0.Type().ID(); {
95 case super.IsUnsigned(id):
96 result := val0.Uint()
97 for _, val := range args[1:] {
98 v, ok := coerce.ToUint(val, super.TypeUint64)
99 if !ok {
100 return r.sctx.WrapError(r.name+": not a number", val)
101 }
102 result = r.fn.Uint64(result, v)
103 }
104 return super.NewUint64(result)
105 case super.IsSigned(id):
106 result := val0.Int()
107 for _, val := range args[1:] {
108 //XXX this is really bad because we silently coerce
109 // floats to ints if we hit a float first
110 v, ok := coerce.ToInt(val, super.TypeInt64)
111 if !ok {
112 return r.sctx.WrapError(r.name+": not a number", val)
113 }
114 result = r.fn.Int64(result, v)
115 }
116 return super.NewInt64(result)
117 case super.IsFloat(id):
118 //XXX this is wrong like math aggregators...
119 // need to be more robust and adjust type as new types encountered
120 result := val0.Float()
121 for _, val := range args[1:] {
122 v, ok := coerce.ToFloat(val, super.TypeFloat64)
123 if !ok {
124 return r.sctx.WrapError(r.name+": not a number", val)
125 }
126 result = r.fn.Float64(result, v)
127 }
128 return super.NewFloat64(result)
129 }
130 return r.sctx.WrapError(r.name+": not a number", val0)
131}
132
133type Round struct {
134 sctx *super.Context

Callers

nothing calls this directly

Calls 15

IsUnsignedFunction · 0.92
ToUintFunction · 0.92
NewUint64Function · 0.92
IsSignedFunction · 0.92
ToIntFunction · 0.92
NewInt64Function · 0.92
IsFloatFunction · 0.92
ToFloatFunction · 0.92
NewFloat64Function · 0.92
WrapErrorMethod · 0.80
FloatMethod · 0.80
Float64Method · 0.80

Tested by

no test coverage detected