CLHEP VERSION Reference Documentation
CLHEP Home Page
CLHEP Documentation
CLHEP Bug Reports
GenericFunctions
src
Power.cc
Go to the documentation of this file.
1
// -*- C++ -*-
2
// $Id: Power.cc,v 1.4 2003/10/10 17:40:39 garren Exp $
3
#include "
CLHEP/GenericFunctions/Power.hh
"
4
#include <cmath>
// for pow()
5
6
namespace
Genfun
{
7
FUNCTION_OBJECT_IMP
(Power)
8
9
Power
::
Power
(
int
n):
10
_intPower(n),
11
_asInteger(true)
12
{}
13
14
Power::Power
(
unsigned
int
n):
15
_intPower(n),
16
_asInteger(true)
17
{}
18
19
Power::Power
(
double
n):
20
_doublePower(n),
21
_asInteger(false)
22
{}
23
24
Power::Power
(
const
Power
& right)
25
:
AbsFunction
(right),
26
_doublePower(right._doublePower),
27
_intPower(right._intPower),
28
_asInteger(right._asInteger)
29
{}
30
31
Power::~Power
() {
32
}
33
34
double
Power::operator()
(
double
x)
const
{
35
if
(_asInteger) {
36
if
(_intPower==0) {
37
return
1;
38
}
39
else
if
(_intPower>0) {
40
double
f
= 1;
41
for
(
int
i=0;i<_intPower;i++) {
42
f
*=x;
43
}
44
return
f
;
45
}
46
else
{
47
double
f
= 1;
48
for
(
int
i=0;i<-_intPower;i++) {
49
f
/=x;
50
}
51
return
f
;
52
}
53
}
54
else
{
55
return
std::pow(x,_doublePower);
56
}
57
58
}
59
60
61
62
Derivative
Power::partial
(
unsigned
int
)
const
{
63
if
(_asInteger) {
64
const
AbsFunction
& fPrime = _intPower*
Power
(_intPower-1);
65
return
Derivative
(&fPrime);
66
}
67
else
{
68
const
AbsFunction
& fPrime = _doublePower*
Power
(_doublePower-1);
69
return
Derivative
(&fPrime);
70
}
71
72
}
73
74
75
}
// namespace Genfun
FUNCTION_OBJECT_IMP
#define FUNCTION_OBJECT_IMP(classname)
Definition
CLHEP/GenericFunctions/AbsFunction.hh:156
Power.hh
Genfun::AbsFunction
Definition
GenericFunctions/AbsFunction.hh:48
Genfun::FunctionNoop
Definition
GenericFunctions/FunctionNoop.hh:19
Genfun::Power
Definition
GenericFunctions/Power.hh:19
Genfun::Power::Power
Power(double n)
Definition
Power.cc:19
Genfun::Power::operator()
virtual double operator()(double argument) const
Definition
Power.cc:34
Genfun::Power::~Power
virtual ~Power()
Definition
Power.cc:31
Genfun::Power::partial
Derivative partial(unsigned int) const
Definition
Power.cc:62
f
void f(void g())
Definition
excDblThrow.cc:38
Genfun
Definition
CLHEP/GenericFunctions/Abs.hh:14
Genfun::Derivative
FunctionNoop Derivative
Definition
CLHEP/GenericFunctions/AbsFunction.hh:42
Generated by
1.12.0