calc method

  1. @override
num? calc(
  1. MathVariableValues values, {
  2. MathCustomFunctionsImplemented customFunctions = const MathCustomFunctionsImplemented({}),
})
override

Generalized value for all sorts of math expressions, but result is not guaranteed.

Tries to return the most appropriate result for given object type. For example, when working with MathNode, it always returns its MathNode.calc result. For MathComparisonEquation, a value of subnodes is being returned but only if they equal, else null will be returned. For MathComparisonGreater and MathComparisonLess returns a greater or a smaller value accordingly only if the expression is true.

Implementation

@override
num? calc(
  MathVariableValues values, {
  MathCustomFunctionsImplemented customFunctions =
      const MathCustomFunctionsImplemented({}),
}) {
  final leftResult = left.calc(
    values,
    customFunctions: customFunctions,
  );
  if (leftResult == null) return null;

  final rightResult = right.calc(
    values,
    customFunctions: customFunctions,
  );
  if (rightResult == null) return null;

  if (leftResult >= rightResult) return leftResult;
  return rightResult;
}