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

Method abs

runtime/vam/expr/function/math.go:30–65  ·  view source on GitHub ↗
(vec vector.Any)

Source from the content-addressed store, hash-verified

28}
29
30func (a *Abs) abs(vec vector.Any) vector.Any {
31 switch vec := vec.(type) {
32 case *vector.Const:
33 typ := vec.Type()
34 if super.IsFloat(typ.ID()) {
35 v := math.Abs(vector.FloatValue(vec, 0))
36 return vector.NewConstFloat(typ, v, vec.Len())
37 }
38 v := vector.IntValue(vec, 0)
39 if v < 0 {
40 v = -v
41 }
42 return vector.NewConstInt(typ, v, vec.Len())
43 case *vector.View:
44 return vector.Pick(a.abs(vec.Any), vec.Index)
45 case *vector.Dict:
46 return vector.NewDict(a.abs(vec.Any), vec.Index, vec.Counts)
47 case *vector.Int:
48 var ints []int64
49 for _, v := range vec.Values {
50 if v < 0 {
51 v = -v
52 }
53 ints = append(ints, v)
54 }
55 return vector.NewInt(vec.Type(), ints)
56 case *vector.Float:
57 var floats []float64
58 for _, v := range vec.Values {
59 floats = append(floats, math.Abs(v))
60 }
61 return vector.NewFloat(vec.Type(), floats)
62 default:
63 panic(vec)
64 }
65}
66
67type Ceil struct {
68 sctx *super.Context

Callers 1

CallMethod · 0.95

Calls 12

IsFloatFunction · 0.92
FloatValueFunction · 0.92
NewConstFloatFunction · 0.92
IntValueFunction · 0.92
NewConstIntFunction · 0.92
PickFunction · 0.92
NewDictFunction · 0.92
NewIntFunction · 0.92
NewFloatFunction · 0.92
TypeMethod · 0.65
IDMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected