Skip to content

Commit

Permalink
Extending operators
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtahu committed Apr 25, 2013
1 parent 0dbea4f commit 2aa2379
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion LangS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,30 @@ string getValue(string name){
* @return The result of the operation on the two values.
*/
string binOP(string op, string a, string b){
if(!op.compare("+")){
try{
double x=str2num(a);
double y=str2num(b);
return num2str(x+y);
}catch(string tx){
return a+b;
}
}//end try
}else if(!op.compare("-")){
try{
double x=str2num(a);
double y=str2num(b);
return num2str(x-y);
}catch(string tx){
return "NaN";
}//end try
}else if(!op.compare("*")){
try{
double x=str2num(a);
double y=str2num(b);
return num2str(x*y);
}catch(string tx){
return "NaN";
}//end try
}else return a+b;
}//end binOP

0 comments on commit 2aa2379

Please sign in to comment.