CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

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 $
4 #include <cmath> // for pow()
5 
6 namespace Genfun {
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 
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
Genfun::Power::Power
Power(double n)
Definition: Power.cc:19
Genfun::Derivative
FunctionNoop Derivative
Definition: CLHEP/GenericFunctions/AbsFunction.hh:40
Genfun::AbsFunction
Definition: CLHEP/GenericFunctions/AbsFunction.hh:48
Genfun::Power::~Power
virtual ~Power()
Definition: Power.cc:31
CLHEP::detail::n
n
Definition: Ranlux64Engine.cc:85
f
void f(void g())
Definition: excDblThrow.cc:38
Genfun::Power::partial
Derivative partial(unsigned int) const
Definition: Power.cc:62
Power.hh
Genfun::FunctionNoop
Definition: CLHEP/GenericFunctions/FunctionNoop.hh:19
i
long i
Definition: JamesRandomSeeding.txt:27
Genfun::Power::operator()
virtual double operator()(double argument) const
Definition: Power.cc:34
Genfun::Power
Definition: CLHEP/GenericFunctions/Power.hh:19
x
any side effects of that construction would occur twice The semantics of throw x
Definition: whyZMthrowRethrows.txt:37
FUNCTION_OBJECT_IMP
#define FUNCTION_OBJECT_IMP(classname)
Definition: CLHEP/GenericFunctions/AbsFunction.hh:156
Genfun
Definition: CLHEP/GenericFunctions/Abs.hh:14