Exemplo n.º 1
0
bool EXParser::evaluateFunction(std::string &_expression, const int index, EXFunctionSet::iterator fiter)

{

	std::string paramExpression = isolateParenthesisExpression(_expression, index);

	size_t expressionLen = paramExpression.length();

	if(expressionLen == 0){
	  mErrorStr = "function parameter error";
	  return false;
	}

	if(!priorityLoop(paramExpression))
	  return false;

	double value = fiter->second((double)atof(paramExpression.c_str()));

	if(isInf(value)){
	  mErrorStr = "infinity error";
	  return false;
	}

	if(isNan(value)){
	  mErrorStr = "not a number error";
	  return false;
	}

	steps.push_back(EXSolveStep(fiter->first+"("+paramExpression+") -> "+dblToStr(value), ""));

	_expression.replace(index-fiter->first.length(), fiter->first.length()+expressionLen+2, dblToStr(value));


	return true;
}
Exemplo n.º 2
0
void EXParser::evaluateFunction(std::string &_expression, const int index, EXFunctionSet::iterator fiter)
{
	std::string paramExpression = isolateParenthesisExpression(_expression, index);
	size_t expressionLen = paramExpression.length();
	if(expressionLen == 0){
		throw EXError("function_parameter_error", ErrorIndex::FUNCTION_PARAMETER_ERROR);
	}
	priorityLoop(paramExpression);
	double value = fiter->second((double)atof(paramExpression.c_str()));
	if(isInf(value)){
		throw EXError("infinity_error", ErrorIndex::INFINITY_ERROR);
	}
	if(isNan(value)){
		throw EXError("not_a_number", ErrorIndex::NAN_ERROR);
	}
	steps.push_back(EXSolveStep(fiter->first+"("+paramExpression+") -> "+dblToStr(value), ""));
	_expression.replace(index-fiter->first.length(), fiter->first.length()+expressionLen+2, dblToStr(value));

}