Commit c698141a authored by peastman's avatar peastman
Browse files

Expression parser tolerates a + in front of an exponent

parent 73f7c14e
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2009-2011 Stanford University and the Authors. * * Portions copyright (c) 2009-2013 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -112,7 +112,7 @@ ParseToken Parser::getNextToken(const string& expression, int start) { ...@@ -112,7 +112,7 @@ ParseToken Parser::getNextToken(const string& expression, int start) {
} }
if ((c == 'e' || c == 'E') && !foundExp) { if ((c == 'e' || c == 'E') && !foundExp) {
foundExp = true; foundExp = true;
if (pos < (int) expression.size()-1 && expression[pos+1] == '-') if (pos < (int) expression.size()-1 && (expression[pos+1] == '-' || expression[pos+1] == '+'))
pos++; pos++;
continue; continue;
} }
......
...@@ -175,6 +175,7 @@ int main() { ...@@ -175,6 +175,7 @@ int main() {
verifyEvaluation("5*2", 10.0); verifyEvaluation("5*2", 10.0);
verifyEvaluation("2*3+4*5", 26.0); verifyEvaluation("2*3+4*5", 26.0);
verifyEvaluation("2^-3", 0.125); verifyEvaluation("2^-3", 0.125);
verifyEvaluation("1e+2", 100.0);
verifyEvaluation("-x", 2.0, 3.0, -2.0); verifyEvaluation("-x", 2.0, 3.0, -2.0);
verifyEvaluation("y^-x", 3.0, 2.0, 0.125); verifyEvaluation("y^-x", 3.0, 2.0, 0.125);
verifyEvaluation("1/-x", 3.0, 2.0, -1.0/3.0); verifyEvaluation("1/-x", 3.0, 2.0, -1.0/3.0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment