CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testBug66214.cc File Reference
#include <iostream>
#include <fstream>
#include <CLHEP/Evaluator/Evaluator.h>

Go to the source code of this file.

Functions

double eval (std::string expr, int &numbad, std::ofstream &os)
 
int main ()
 

Function Documentation

◆ eval()

double eval ( std::string  expr,
int &  numbad,
std::ofstream &  os 
)

Definition at line 11 of file testBug66214.cc.

12{
13 static HepTool::Evaluator *ev=0;
14 if(ev == 0) ev = new HepTool::Evaluator();
15 ev->setStdMath(); // set standard constants and functions
16 ev->setSystemOfUnits(); // set SI units
17
18 double v = ev->evaluate(expr.data());
19
20 os << "CALC> " << expr << ": ";
21 if(ev->status() != HepTool::Evaluator::OK) {
22 os << ev->error_name() << std::endl;
23 ++numbad;
24 } else {
25 os << v << std::endl;
26 }
27 return v;
28}
void setSystemOfUnits(double meter=1.0, double kilogram=1.0, double second=1.0, double ampere=1.0, double kelvin=1.0, double mole=1.0, double candela=1.0)
double evaluate(const char *expression)
Definition: Evaluator.cc:637
std::string error_name() const
Definition: Evaluator.cc:676
int status() const
Definition: Evaluator.cc:657

Referenced by main().

◆ main()

int main ( )

Definition at line 30 of file testBug66214.cc.

31{
32
33 int numbad = 0;
34 double result;
35 // many of these expressions fail in releases prior to 2.0.4.7
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.,
51 4., 4., -4., 66., 6.,
52 4., 4., -4., 4., 4.,
53 -6., -6., -6., -6. };
54 std::string exp2[3] = { "sin(45*deg)", "sin(45*pi/-180)", "232/22" };
55
56 std::ofstream os("testBug66214.cout");
57
58 for(int i=0; i<43; ++i ) {
59 result=eval(exp[i],numbad,os);
60 if( result != res[i] ) {
61 ++numbad;
62 os << "ERROR: expected " << res[i] << " got " << result << std::endl;
63 os << std::endl;
64 }
65 }
66
67 // inspect these by hand
68 // return values: 0.707107, -0.707107, 10.5455
69 for(int i=0; i<3; ++i ) {
70 eval(exp2[i],numbad,os);
71 }
72
73 return numbad;
74}
double eval(std::string expr, int &numbad, std::ofstream &os)
Definition: testBug66214.cc:11