eval method

  1. @override
Object eval(
  1. DataInstance? model,
  2. EvaluationContext context
)
override

Evaluates against model (usually the context's main instance) in context. The result is a bool, double, String, DateTime, XPathNodeset or a value returned by a custom function.

Implementation

@override
Object eval(DataInstance? model, EvaluationContext context) {
  final x = toNumeric(a.eval(model, context));
  final y = toNumeric(b.eval(model, context));
  return switch (op) {
    ArithOp.add => x + y,
    ArithOp.subtract => x - y,
    ArithOp.multiply => x * y,
    ArithOp.divide => x / y,
    // Java's % keeps the dividend's sign, like Dart's remainder().
    ArithOp.modulo => x.remainder(y),
  };
}