I have to do very simple mathematical calculatation like:
"2*(3+4) + 5"
where the formula is given as a string.
Is there any class which can handle this, i.e. return the result?
This functionality has to be included somewhere in TFormula, but how do I access it???
the easiest way is to use
result=gROOT->ProcessLineFast("2*(3+4) + 5") See the doc on TROOT::ProcessLineFast at http://root.cern.ch/root/html/TROOT#TROOT:ProcessLine.
This works nice for integers. What if I have doubles?
double result = gROOT->ProcessLine(“sqrt(45.5)”)
Acoording to the documentation of TROOT:
void ProcessLine(const char* line, Int_t* error = 0)
It returns a void!
Consequently I get a “error: void value not ignored as it ought to be”, when I compile the code.
It works! This saved me a hugh amount of time!
But one little problem remains:
How do I prevent it from printing the result to the screen?
I probably will use this funtion very frequently and thus it would fill my screen output…
Thanks a lot,
Add a semi-colon:
I would have never figured out this trick!