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
virtual double operator()(double argument) const
Definition: Power.cc:34
virtual ~Power()
Definition: Power.cc:31
void f(void g())
Definition: excDblThrow.cc:38
#define FUNCTION_OBJECT_IMP(classname)
Power(double n)
Definition: Power.cc:19
Derivative partial(unsigned int) const
Definition: Power.cc:62