CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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
6namespace Genfun {
8
9Power::Power(int n):
10 _intPower(n),
11 _asInteger(true)
12{}
13
14Power::Power(unsigned int n):
15 _intPower(n),
16 _asInteger(true)
17{}
18
19Power::Power(double n):
20 _doublePower(n),
21 _asInteger(false)
22{}
23
24Power::Power(const Power & right)
25 : AbsFunction(right),
26 _doublePower(right._doublePower),
27 _intPower(right._intPower),
28 _asInteger(right._asInteger)
29{}
30
32}
33
34double 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
62Derivative 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
#define FUNCTION_OBJECT_IMP(classname)
Definition: AbsFunction.hh:149
Power(double n)
Definition: Power.cc:19
virtual ~Power()
Definition: Power.cc:31
Derivative partial(unsigned int) const override
Definition: Power.cc:62
virtual double operator()(double argument) const override
Definition: Power.cc:34
void f(void g())
Definition: excDblThrow.cc:38
Definition: Abs.hh:14
FunctionNoop Derivative
Definition: AbsFunction.hh:42