9#include <CLHEP/Evaluator/Evaluator.h>
11double eval( std::string expr,
int& numbad, std::ofstream& os)
18 double v = ev->
evaluate(expr.data());
20 os <<
"CALC> " << expr <<
": ";
36 std::string exp[43] = {
" +1",
" -1",
"1 + 1",
"1 + -1",
"1 + (-1)",
37 "1 + +1",
"1 + (+1)",
"1 * -1",
"1 * (-1)",
"-1 * 1",
38 "10^-1",
"10^(-1)",
"9*4",
"9 * -4",
"9 * (-4)",
39 "4*---2",
"4*(---2)",
"4*(-(--2))",
"4*(--(-2))",
"4*(-(-(-2)))",
40 "4*--2",
"4*(--2)",
"4*(-(-2))",
"-5^2",
"9*4+2",
41 "231/-11",
"231/-11+10",
"231/-11/3",
"(231/-11)+10",
42 "100/5^2",
"100/+5^2",
"100/-5^2",
"9*4+30",
"9*4+-30",
43 "100/(5^2)",
"100/(+5^2)",
"100/(-5^2)",
"100/(-5)^2",
"100/((-5)^2)",
44 "-9*4+30",
"9*-4+30",
"9*(-4)+30",
"(9*-4)+30" };
45 double res[43] = { 1., -1., 2., 0., 0.,
46 2., 2., -1., -1., -1.,
47 0.1, 0.1, 36., -36., -36.,
48 -8., -8., -8., -8., -8.,
49 8., 8., 8., -25., 38.,
50 -21., -11., -7., -11.,
54 std::string exp2[3] = {
"sin(45*deg)",
"sin(45*pi/-180)",
"232/22" };
56 std::ofstream os(
"testBug66214.cout");
58 for(
int i=0; i<43; ++i ) {
59 result=
eval(exp[i],numbad,os);
60 if( result != res[i] ) {
62 os <<
"ERROR: expected " << res[i] <<
" got " << result << std::endl;
69 for(
int i=0; i<3; ++i ) {
70 eval(exp2[i],numbad,os);
double eval(std::string expr, int &numbad, std::ofstream &os)