(args []super.Value)
| 90 | } |
| 91 | |
| 92 | func (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 | |
| 133 | type Round struct { |
| 134 | sctx *super.Context |
nothing calls this directly
no test coverage detected