computeCube function

double computeCube(
  1. String formula,
  2. double value
)

Computes Y from a given X and function formula and returns it as a double for cubic functions.

Implementation

double computeCube(String formula, double value) {
  double result = 0;
  if (astParser(formula) == 'CUBE_FUNCTION') {
    double constant = irParser(formula)[0];
    double factorToBeCubed = irParser(formula)[1];
    double factorToBeSquared = irParser(formula)[2];
    double factorToBeMultiplied = irParser(formula)[3];
    result = constant +
        (factorToBeCubed * pow(value, 3)) +
        (factorToBeSquared * pow(value, 2)) +
        (factorToBeMultiplied * value);
  } else {}
  return result;
}