Commit 73a45ff5 by Lynn Garren

### fix unary +/- bug

parent 8404a86e
 2012-01-31 Lynn Garren and Mark Fischler * Evaluator/src/Evaluator.cc: fix a problem with unary +/- and exponentials * Evaluator/test/testBug90848.cc: new test for bug #90848 ============================== 16.12.11 Release CLHEP-2.1.2.0 ============================== ... ...
 2012-01-31 Lynn Garren and Mark Fischler * src/Evaluator.cc: fix a problem with unary +/- and exponentials * test/testBug90848.cc: new test for bug #90848 ============================== 16.12.11 Release CLHEP-2.1.2.0 ============================== ... ... @@ -11,8 +17,7 @@ 23.07.10 Release CLHEP-2.1.0.0 ============================== 2010-06-29 Mark Fischler 2010-06-29 * src/Evaluator.cc: Improve the logic so that unary plus and minus work as expected. See bug report #66214. ... ...
 ... ... @@ -409,8 +409,8 @@ static int engine(pchar begin, pchar end, double & result, { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4 }, // < { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 1, 1, 1, 1, 4 }, // + { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 1, 1, 1, 1, 4 }, // - { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4 }, // unary + { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4 }, // unary - { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 1, 4 }, // unary + { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 1, 4 }, // unary - { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 2, 2, 1, 4 }, // * { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 2, 2, 1, 4 }, // / { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4 } // ^ ... ...
 clhep_test( testEvaluator ) clhep_test( testBug66214 SIMPLE ) clhep_test( testBug90848 SIMPLE )
 ... ... @@ -27,14 +27,14 @@ CXXLINK = \$(CXXLD) \$(AM_CXXFLAGS) \$(CXXFLAGS) \$(AM_LDFLAGS) \$(LDFLAGS) \ # Identify executables needed during testing: check_PROGRAMS = \ testEvaluator testBug66214 testEvaluator testBug66214 testBug90848 check_SCRIPTS = \ testEvaluator.sh # Identify test(s) to run when 'make check' is requested: TESTS = \ testEvaluator.sh testBug66214 testEvaluator.sh testBug66214 testBug90848 # Identify the test(s) for which failure is the intended outcome: XFAIL_TESTS = ... ... @@ -42,6 +42,7 @@ XFAIL_TESTS = # Identify the dependencies on a per-test basis: testEvaluator_SOURCES = testEvaluator.cc testBug66214_SOURCES = testBug66214.cc testBug90848_SOURCES = testBug90848.cc # Identify input data file(s) and prototype output file(s): EXTRA_DIST = \ ... ...
 ... ... @@ -33,27 +33,29 @@ int main() int numbad = 0; double result; // many of these expressions fail in releases prior to 2.0.4.7 std::string exp[38] = { " +1", " -1", "1 + 1", "1 + -1","1 + (-1)", std::string exp[43] = { " +1", " -1", "1 + 1", "1 + -1","1 + (-1)", "1 + +1","1 + (+1)", "1 * -1","1 * (-1)", "-1 * 1", "10^-1", "10^(-1)", "9*4", "9 * -4","9 * (-4)", "4*---2","4*(---2)","4*(-(--2))","4*(--(-2))","4*(-(-(-2)))", "4*--2", "4*(--2)", "4*(-(-2))", "-5^2", "9*4+2", "231/-11","231/-11+10","231/-11/3","(231/-11)+10", "100/5^2","100/+5^2","100/-5^2", "9*4+30", "9*4+-30", "100/(5^2)","100/(+5^2)","100/(-5^2)", "100/(-5)^2", "100/((-5)^2)", "-9*4+30","9*-4+30","9*(-4)+30","(9*-4)+30" }; double res[38] = { 1., -1., 2., 0., 0., double res[43] = { 1., -1., 2., 0., 0., 2., 2., -1., -1., -1., 0.1, 0.1, 36., -36., -36., -8., -8., -8., -8., -8., 8., 8., 8., 25., 38., -21., -11., -7., -11., 4., 4., 4., 66., 6., -6., -6., -6., -6. }; 8., 8., 8., -25., 38., -21., -11., -7., -11., 4., 4., -4., 66., 6., 4., 4., -4., 4., 4., -6., -6., -6., -6. }; std::string exp2[3] = { "sin(45*deg)", "sin(45*pi/-180)", "232/22" }; std::ofstream os("testBug66214.cout"); for(int i=0; i<38; ++i ) { for(int i=0; i<43; ++i ) { result=eval(exp[i],numbad,os); if( result != res[i] ) { ++numbad; ... ...
 // test Bug #90848 in CLHEP::Evaluator // Author: Tom Roberts #include #include #include #include "CLHEP/Evaluator/Evaluator.h" class MyEvaluator : public HepTool::Evaluator { public: MyEvaluator() : HepTool::Evaluator() { setStdMath(); } bool isOK() { return status() == OK; } double evaluate(const char *e) { double v = HepTool::Evaluator::evaluate(e); if(status() != OK) v = std::numeric_limits::quiet_NaN(); return v; } }; struct Test { const char *expr; double value1; // x=1, y=2, z=3 double value2; // x=10, y=-20 z=-30 }; Test tests[] = { { "x", 1.0, 10.0}, { "y", 2.0, -20.0}, { "z", 3.0, -30.0}, { "x+y", 3.0, -10.0}, { "-z", -3.0, 30.0}, { "0-z", -3.0, 30.0}, { "0 - -z", 3.0, -30.0}, { "10/-x", -10.0, -1.0}, { "exp(-y)*exp(y)", 1.0, 1.0}, { "exp(-y^2)*exp(y^2)", 1.0, 1.0}, { "-5*x", -5.0, -50.0}, { "5+-x", 4.0, -5.0}, { "5+(-x)", 4.0, -5.0}, { "5*-x", -5.0, -50.0}, { "5*(-x)", -5.0, -50.0}, { "-z^2", -9.0, -900.0}, { "0-z^2", -9.0, -900.0}, { "exp(-0.2*z^2)*exp(0.2*z^2)", 1.0, 1.0}, { "exp(0.2*-z^2)*exp(0.2*z^2)", 1.0, 1.0}, { "exp(-z^2*0.2)*exp(0.2*z^2)", 1.0, 1.0}, { "exp(0.2*-(z^2))*exp(0.2*z^2)", 1.0, 1.0}, { "exp(-(z^2)*0.2)*exp(0.2*z^2)", 1.0, 1.0}, { "exp(-0.2*z)*exp(0.2*z)", 1.0, 1.0}, { "exp(0.2*-z)*exp(0.2*z)", 1.0, 1.0}, { "exp(-z*0.2)*exp(0.2*z)", 1.0, 1.0}, }; int main(int argc, char *argv[]) { MyEvaluator e; e.setVariable("x",1.0); e.setVariable("y",2.0); e.setVariable("z",3.0); //printf("x=1.0 y=2.0 z=3.0\n"); int err=0; for(unsigned i=0; i 1E-12 || !e.isOK()) { printf("%s = %.6f should be %.6f\n",tests[i].expr, e.evaluate(tests[i].expr),tests[i].value1); err = 1; } } e.setVariable("x",10.0); e.setVariable("y",-20.0); e.setVariable("z",-30.0); //printf("x=10.0 y=-20.0 z=-30.0\n"); for(unsigned i=0; i 1E-12 || !e.isOK()) { printf("%s = %.6f should be %.6f\n",tests[i].expr, e.evaluate(tests[i].expr),tests[i].value2); err = 1; } } double v=e.evaluate("unknown(0.0)"); if(!isnan(v) || e.isOK()) { printf("%s succeeded\n","unknown(0.0)"); err=1; } v = e.evaluate("unknown+0.0"); if(!isnan(v) || e.isOK()) { printf("%s succeeded\n","unknown+0.0"); err=1; } exit(err); }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!