CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testGenericFunctions.cc File Reference
#include "CLHEP/GenericFunctions/GenericFunctions.hh"
#include "CLHEP/GenericFunctions/Sin.hh"
#include "CLHEP/GenericFunctions/Cos.hh"
#include "CLHEP/GenericFunctions/defs.h"
#include <float.h>
#include <cassert>
#include <cmath>
#include <iostream>

Go to the source code of this file.

Functions

int main (int, char **)
 

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 11 of file testGenericFunctions.cc.

11 {
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 g(shared_ptr< X >)