CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

testBug90848.cc
Go to the documentation of this file.
1 // test Bug #90848 in CLHEP::Evaluator
2 // Author: Tom Roberts
3 
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <cmath>
7 #include <limits>
8 
11 public:
13  bool isOK() { return status() == OK; }
14  double evaluate(const char *e) {
15  double v = HepTool::Evaluator::evaluate(e);
16  if(status() != OK) v = std::numeric_limits<double>::quiet_NaN();
17  return v;
18  }
19 };
20 
21 struct Test {
22  const char *expr;
23  double value1; // x=1, y=2, z=3
24  double value2; // x=10, y=-20 z=-30
25 };
26 
27 Test tests[] = {
28  { "x", 1.0, 10.0},
29  { "y", 2.0, -20.0},
30  { "z", 3.0, -30.0},
31  { "x+y", 3.0, -10.0},
32  { "-z", -3.0, 30.0},
33  { "0-z", -3.0, 30.0},
34  { "0 - -z", 3.0, -30.0},
35  { "10/-x", -10.0, -1.0},
36  { "exp(-y)*exp(y)", 1.0, 1.0},
37  { "exp(-y^2)*exp(y^2)", 1.0, 1.0},
38  { "-5*x", -5.0, -50.0},
39  { "5+-x", 4.0, -5.0},
40  { "5+(-x)", 4.0, -5.0},
41  { "5*-x", -5.0, -50.0},
42  { "5*(-x)", -5.0, -50.0},
43  { "-z^2", -9.0, -900.0},
44  { "0-z^2", -9.0, -900.0},
45  { "exp(-0.2*z^2)*exp(0.2*z^2)", 1.0, 1.0},
46  { "exp(0.2*-z^2)*exp(0.2*z^2)", 1.0, 1.0},
47  { "exp(-z^2*0.2)*exp(0.2*z^2)", 1.0, 1.0},
48  { "exp(0.2*-(z^2))*exp(0.2*z^2)", 1.0, 1.0},
49  { "exp(-(z^2)*0.2)*exp(0.2*z^2)", 1.0, 1.0},
50  { "exp(-0.2*z)*exp(0.2*z)", 1.0, 1.0},
51  { "exp(0.2*-z)*exp(0.2*z)", 1.0, 1.0},
52  { "exp(-z*0.2)*exp(0.2*z)", 1.0, 1.0},
53 };
54 
55 int main() {
56  MyEvaluator e;
57 
58  e.setVariable("x",1.0);
59  e.setVariable("y",2.0);
60  e.setVariable("z",3.0);
61 //printf("x=1.0 y=2.0 z=3.0\n");
62  int err=0;
63  for(unsigned i=0; i<sizeof(tests)/sizeof(Test); ++i) {
64  double v=e.evaluate(tests[i].expr);
65  if(std::isnan(v) || std::fabs(v-tests[i].value1) > 1E-12 || !e.isOK()) {
66  printf("%s = %.6f should be %.6f\n",tests[i].expr,
68  err = 1;
69  }
70  }
71 
72  e.setVariable("x",10.0);
73  e.setVariable("y",-20.0);
74  e.setVariable("z",-30.0);
75 //printf("x=10.0 y=-20.0 z=-30.0\n");
76  for(unsigned i=0; i<sizeof(tests)/sizeof(Test); ++i) {
77  double v=e.evaluate(tests[i].expr);
78  if(std::isnan(v) || std::fabs(v-tests[i].value2) > 1E-12 || !e.isOK()) {
79  printf("%s = %.6f should be %.6f\n",tests[i].expr,
81  err = 1;
82  }
83  }
84 
85  double v=e.evaluate("unknown(0.0)");
86  if(!std::isnan(v) || e.isOK()) {
87  printf("%s succeeded\n","unknown(0.0)");
88  err=1;
89  }
90 
91  v = e.evaluate("unknown+0.0");
92  if(!std::isnan(v) || e.isOK()) {
93  printf("%s succeeded\n","unknown+0.0");
94  err=1;
95  }
96 
97  exit(err);
98 }
tests
Test tests[]
Definition: testBug90848.cc:27
HepTool::Evaluator
Definition: CLHEP/Evaluator/Evaluator.h:26
HepTool::Evaluator::Evaluator
Evaluator()
Definition: Evaluator.cc:597
MyEvaluator
Definition: testBug90848.cc:10
HepTool::Evaluator::status
int status() const
Definition: Evaluator.cc:632
Test::value1
double value1
Definition: testBug90848.cc:23
main
int main()
Definition: testBug90848.cc:55
v
they are gone ZOOM Features Discontinued The following features of the ZOOM package were felt to be extreme overkill These have been after checking that no existing user code was utilizing as in SpaceVector v
Definition: keyMergeIssues.doc:324
HepTool
Definition: CLHEP/Evaluator/Evaluator.h:10
HepTool::Evaluator::setVariable
void setVariable(const char *name, double value)
Definition: Evaluator.cc:688
MyEvaluator::evaluate
double evaluate(const char *e)
Definition: testBug90848.cc:14
MyEvaluator::MyEvaluator
MyEvaluator()
Definition: testBug90848.cc:12
HepTool::Evaluator::OK
@ OK
Definition: CLHEP/Evaluator/Evaluator.h:40
i
long i
Definition: JamesRandomSeeding.txt:27
MyEvaluator::isOK
bool isOK()
Definition: testBug90848.cc:13
HepTool::Evaluator::setStdMath
void setStdMath()
Definition: setStdMath.cc:31
Test::expr
const char * expr
Definition: testBug90848.cc:22
Test::value2
double value2
Definition: testBug90848.cc:24
exit
it has advantages For I leave the ZMthrows but substitute I replaced ZMthrow with ZMthrowA in this package when will issue its message and exit(-1). Also
HepTool::Evaluator::evaluate
double evaluate(const char *expression)
Definition: Evaluator.cc:612
Evaluator.h
Test
Definition: testBug90848.cc:21