Skip to content

Commit

Permalink
Added macro for checknumber/do operation
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtahu committed Apr 25, 2013
1 parent 2aa2379 commit 73dbbe6
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions LangS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ string getValue(string name){
return varTable[name];
}//end getValue

#define TRY_NUM(OP) try{ \
double x=str2num(a); \
double y=str2num(b); \
return num2str(x OP y); \
}catch(string tx){ \
return "NaN"; \
}//end try \
/**
* Performs an operation on two values.
* @param op The operation to perform
Expand All @@ -71,21 +79,11 @@ string binOP(string op, string a, string b){
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
TRY_NUM(-);
}else if(!op.compare("*")){
try{
double x=str2num(a);
double y=str2num(b);
return num2str(x*y);
}catch(string tx){
return "NaN";
}//end try
TRY_NUM(*);
}else if(!op.compare("/")){
TRY_NUM(/);
}else return a+b;
}//end binOP

0 comments on commit 73dbbe6

Please sign in to comment.