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

Function NewArithmetic

runtime/sam/expr/eval.go:426–441  ·  view source on GitHub ↗

NewArithmetic compiles an expression of the form "expr1 op expr2" for the arithmetic operators +, -, *, /

(sctx *super.Context, op string, lhs, rhs Evaluator)

Source from the content-addressed store, hash-verified

424// NewArithmetic compiles an expression of the form "expr1 op expr2"
425// for the arithmetic operators +, -, *, /
426func NewArithmetic(sctx *super.Context, op string, lhs, rhs Evaluator) (Evaluator, error) {
427 n := newNumeric(sctx, lhs, rhs)
428 switch op {
429 case "+":
430 return &Add{sctx: sctx, operands: n}, nil
431 case "-":
432 return &Subtract{sctx: sctx, operands: n}, nil
433 case "*":
434 return &Multiply{sctx: sctx, operands: n}, nil
435 case "/":
436 return &Divide{sctx: sctx, operands: n}, nil
437 case "%":
438 return &Modulo{sctx: sctx, operands: n}, nil
439 }
440 return nil, fmt.Errorf("unknown arithmetic operator: %s", op)
441}
442
443func (a *Add) Eval(this super.Value) super.Value {
444 lhsVal, rhsVal, typ, errVal := a.operands.evalAndPromote(this)

Callers 1

compileBinaryMethod · 0.92

Calls 1

newNumericFunction · 0.85

Tested by

no test coverage detected