Commit 9a52bede authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

ExpressionCalculator: better check for leaf node

parent 09639ed0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ class ExpressionCalculator {
			for (SizeType i = 0; i < 4; ++i) op[i] = '\0';
			SizeType l = str.size();
			if (l == 0) return;
			if (str[l-1] >= '0' && str[l-1]<='9') {
			if (isAfloat(str)) {
				type = NODE_NUMBER;
				value = atof(str.c_str());
			} else {
+11 −2
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ int atoi(String str)
	return std::atoi(str.c_str());
}

double atof(String str)
bool isAfloat(String str)
{
	const SizeType n = str.length();
	for (SizeType i = 0; i < n; ++i) {
@@ -79,9 +79,18 @@ double atof(String str)
		        str[i] == 'e' ||
		        str[i] == 'E' ||
		        str[i] == '.') continue;
		throw RuntimeError("atof received a non-digit\n");
		return false;
	}

	return true;
}

double atof(String str)
{

	if (!isAfloat(str))
		throw RuntimeError("atof received a non-digit " + str + "\n");

	return std::atof(str.c_str());
}

+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ std::istream& operator>>(std::istream&,std::pair<SizeType,SizeType>&);

SizeType log2Integer(SizeType x);

bool isAfloat(String str);

int atoi(String);

double atof(String);