CLHEP VERSION Reference Documentation
CLHEP Home Page
CLHEP Documentation
CLHEP Bug Reports
GenericFunctions
test
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 <assert.h>
7
#include <cmath>
8
9
int
main
(
int
,
char
**) {
10
11
using namespace
Genfun
;
12
13
GENFUNCTION
f
=
Sin
(),
g
=
Cos
();
14
GENPARAMETER
p =
Parameter
(
"Parameter"
, 4.0);
15
16
for
(
double
x
= 0;
x
< 100;
x
++) {
17
// Test Simple Arithmetic Operations Between Functions
18
19
assert (fabs((
f
*
g
) (
x
) - (sin(
x
)*cos(
x
))) <= FLT_EPSILON);
20
assert (fabs((
f
+
g
) (
x
) - (sin(
x
)+cos(
x
))) <= FLT_EPSILON);
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
24
// Test Simple Arithmetic Operations Between Functions and Parameters
25
26
assert (fabs((p*
f
)(
x
)- 4.0*sin(
x
)) <= FLT_EPSILON);
27
assert (fabs((
f
*p)(
x
)- 4.0*sin(
x
)) <= FLT_EPSILON);
28
29
// Test Simple Arithmetic Operations Between Functions and Constants
30
31
assert (fabs((
f
*4.0)(
x
)- 4.0*sin(
x
)) <= FLT_EPSILON);
32
assert (fabs((4.0*
f
)(
x
)- 4.0*sin(
x
)) <= FLT_EPSILON);
33
34
// Test Function composition
35
assert (fabs(((
f
(
g
))(
x
)) - sin(cos(
x
))) <= FLT_EPSILON);
36
37
}
38
39
40
// Test Simple Arithmetic Operations Between Parameters
41
assert (fabs((p*p).getValue()- 4.0*4.0) <= FLT_EPSILON);
42
43
// Test Simple Arithmetic Operations Between Parameters and Constants
44
assert (fabs((4*p).getValue()- 4.0*4.0) <= FLT_EPSILON);
45
assert (fabs((p*4).getValue()- 4.0*4.0) <= FLT_EPSILON);
46
47
// Congratulate the lucky user:
48
std::cout <<
"GenericFunctions autotest has passed"
<< std::endl;
49
return
0;
50
}
Sin.hh
g
int g(shared_ptr< X >)
Definition:
testSharedPtrConvertible.cc:46
Genfun::Sin
Definition:
CLHEP/GenericFunctions/Sin.hh:18
Genfun::GENFUNCTION
const typedef AbsFunction & GENFUNCTION
Definition:
CLHEP/GenericFunctions/AbsFunction.hh:125
main
int main(int, char **)
Definition:
testGenericFunctions.cc:9
Genfun::Cos
Definition:
CLHEP/GenericFunctions/Cos.hh:19
f
void f(void g())
Definition:
excDblThrow.cc:38
Genfun::GENPARAMETER
const typedef AbsParameter & GENPARAMETER
Definition:
CLHEP/GenericFunctions/AbsParameter.hh:74
GenericFunctions.hh
Cos.hh
defs.h
Genfun::Parameter
Definition:
CLHEP/GenericFunctions/Parameter.hh:35
x
any side effects of that construction would occur twice The semantics of throw x
Definition:
whyZMthrowRethrows.txt:37
Genfun
Definition:
CLHEP/GenericFunctions/Abs.hh:14
Generated by
1.8.17