View Single Post
  #1   Spotlight this post!  
Unread 19-02-2014, 21:07
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Function-in-a-line!!! (C/C++)

Since I have started vision processing, these are nifty functions, that I've consicified into a single line so they are out of the way of your real code!

Code:
//string funcs, requiring string and sstream
string bool2str(bool in) { stringstream str; str << in; return str.str(); }

string int2str(int inp) { stringstream str; str << inp; return str.str(); }

string double2str(double in) { stringstream str; str << in; return str.str(); }


//math functions!
double tanDeg(double input) { return tan((input) * pi / 180); }
double hypotenuse(double legA, double legB) { return sqrt(((legA*legA) + (legB*legB))); }
double leg(double hypotenuse, double leg) { return sqrt(((hypotenuse*hypotenuse) - (leg*leg))); }
Give me any feedback and post more of these single-liner c functions!