1 /*!
2 * \file tests/Math/parser5.cxx
3 * \brief
4 *
5 * \author Thomas Helfer
6 * \date 20 déc 2008
7 * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
8 * reserved.
9 * This project is publicly released under either the GNU GPL Licence
10 * or the CECILL-A licence. A copy of thoses licences are delivered
11 * with the sources of TFEL. CEA or EDF may also distribute this
12 * project under specific licensing conditions.
13 */
14
15 #ifdef NDEBUG
16 #undef NDEBUG
17 #endif /* NDEBUG */
18
19 #include<cmath>
20 #include<cassert>
21 #include<cstdlib>
22
23 #include"TFEL/Math/Evaluator.hxx"
24
25 /* coverity [UNCAUGHT_EXCEPT]*/
main()26 int main()
27 {
28 using namespace std;
29 using namespace tfel::math;
30 using namespace tfel::math::parser;
31 vector<string> var(1,"x");
32 vector<string> nvar(1,"a");
33 auto manager = std::make_shared<ExternalFunctionManager>();
34 auto f = std::make_shared<Evaluator>(var,"sin(a*x)",manager);
35 auto h = f->createFunctionByChangingParametersIntoVariables(nvar);
36 h = h->resolveDependencies();
37 assert(h->getNumberOfVariables()==2);
38 h->setVariableValue(0,1.5);
39 h->setVariableValue(1,2.54);
40 assert(abs(h->getValue()-sin(1.5*2.54))<1.e-14);
41
42 #if __GNUC__ != 3
43 auto dh_dx = h->differentiate(0);
44 dh_dx->setVariableValue(0,12.5);
45 dh_dx->setVariableValue(1,3.5412);
46 assert(abs(dh_dx->getValue()-3.5412*cos(3.5412*12.5))<1.e-14);
47 auto dh_da = h->differentiate(1);
48 dh_da->setVariableValue(0,7.98);
49 dh_da->setVariableValue(1,4.1);
50 assert(abs(dh_da->getValue()-7.98*cos(4.1*7.98))<1.e-14);
51 #endif
52
53 return EXIT_SUCCESS;
54 }
55