Parsing of equation

Hi,

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???

Thanks,
Andreas

Hi Amdreas,

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.

Axel.

Thanks Axel!

This works nice for integers. What if I have doubles?

Thanks,
Andreas

eg
double result = gROOT->ProcessLine(“sqrt(45.5)”)

Rene

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.

Andreas

Use:

Double d; gROOT->ProcessLine("Form("*((double*)0x%x)=sqrt(45.5)",&d));
Cheers,
Philippe

Thanks Philippe!
It works! This saved me a hugh amount of time! :smiley:

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,
Andreas

Add a semi-colon:

Double d; gROOT->ProcessLine("Form("*((double*)0x%x)=sqrt(45.5);",&d));
Cheers,
Philippe.

Thanks!
I would have never figured out this trick! :smiley: