evaluate method

  1. @override
dynamic evaluate(
  1. EvaluationType type,
  2. ContextModel context
)
override

Evaluates this expression according to given type and context.

Implementation

@override
dynamic evaluate(EvaluationType type, ContextModel context) {
  final dynamic argEval = arg.evaluate(type, context);

  if (argEval < 0) {
    throw ArgumentError.value(
        argEval, 'Factorial', 'Negative values not supported.');
  } else if (argEval == double.infinity) {
    throw ArgumentError.value(
        argEval, 'Factorial', 'Infinity not supported.');
  }
  if (type == EvaluationType.REAL) {
    dynamic product = 1.0;
    for (int i = 1; i <= argEval.round(); i++) {
      product *= i;
    }
    return product;
  }

  throw UnimplementedError('Can not evaluate $name on $type yet.');
}