CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testGenericFunctions.cc
Go to the documentation of this file.
1#include "CLHEP/GenericFunctions/GenericFunctions.hh"
2#include "CLHEP/GenericFunctions/Sin.hh"
3#include "CLHEP/GenericFunctions/Cos.hh"
4#include "CLHEP/GenericFunctions/defs.h"
5#include <float.h>
6#include <cassert>
7#include <cmath>
8#include <iostream>
9
10
11int main(int, char **) {
12
13 using namespace Genfun;
14
15 GENFUNCTION f = Sin(), g = Cos();
16 GENPARAMETER p = Parameter("Parameter", 4.0);
17
18 for (double x = 0; x < 100; x++) {
19 // Test Simple Arithmetic Operations Between Functions
20
21 assert (fabs((f*g) (x) - (sin(x)*cos(x))) <= FLT_EPSILON);
22 assert (fabs((f+g) (x) - (sin(x)+cos(x))) <= FLT_EPSILON);
23 assert (fabs((f-g) (x) - (sin(x)-cos(x))) <= FLT_EPSILON);
24 assert (fabs((f/g) (x) - (sin(x)/cos(x))) <= FLT_EPSILON);
25
26 // Test Simple Arithmetic Operations Between Functions and Parameters
27
28 assert (fabs((p*f)(x)- 4.0*sin(x)) <= FLT_EPSILON);
29 assert (fabs((f*p)(x)- 4.0*sin(x)) <= FLT_EPSILON);
30
31 // Test Simple Arithmetic Operations Between Functions and Constants
32
33 assert (fabs((f*4.0)(x)- 4.0*sin(x)) <= FLT_EPSILON);
34 assert (fabs((4.0*f)(x)- 4.0*sin(x)) <= FLT_EPSILON);
35
36 // Test Function composition
37 assert (fabs(((f(g))(x)) - sin(cos(x))) <= FLT_EPSILON);
38
39 }
40
41
42 // Test Simple Arithmetic Operations Between Parameters
43 assert (fabs((p*p).getValue()- 4.0*4.0) <= FLT_EPSILON);
44
45 // Test Simple Arithmetic Operations Between Parameters and Constants
46 assert (fabs((4*p).getValue()- 4.0*4.0) <= FLT_EPSILON);
47 assert (fabs((p*4).getValue()- 4.0*4.0) <= FLT_EPSILON);
48
49 // Congratulate the lucky user:
50 std::cout << "GenericFunctions autotest has passed" << std::endl;
51 return 0;
52}
void f(void g())
Definition: excDblThrow.cc:38
Definition: Abs.hh:14
int main()
Definition: testBug66214.cc:30
int g(shared_ptr< X >)