CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Power.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: Power.cc,v 1.4 2003/10/10 17:40:39 garren Exp $
00003 #include "CLHEP/GenericFunctions/Power.hh"
00004 #include <cmath>      // for pow()
00005 
00006 namespace Genfun {
00007 FUNCTION_OBJECT_IMP(Power)
00008 
00009 Power::Power(int n):
00010     _intPower(n),
00011     _asInteger(true)
00012 {}
00013 
00014 Power::Power(unsigned int n):
00015     _intPower(n),
00016     _asInteger(true)
00017 {}
00018 
00019 Power::Power(double n):
00020     _doublePower(n),
00021     _asInteger(false)
00022 {}
00023 
00024 Power::Power(const Power & right)
00025     : _doublePower(right._doublePower),
00026       _intPower(right._intPower),
00027       _asInteger(right._asInteger)
00028 {}
00029 
00030 Power::~Power() {
00031 }
00032 
00033 double Power::operator() (double x) const {
00034     if (_asInteger) {
00035         if (_intPower==0) {
00036             return 1;
00037         }
00038         else if (_intPower>0) {
00039             double f = 1;
00040             for (int i=0;i<_intPower;i++) {
00041                 f *=x;
00042             }
00043             return f;
00044         }
00045         else {
00046             double f = 1;
00047             for (int i=0;i<-_intPower;i++) {
00048                 f /=x;
00049             }
00050             return f;
00051         }           
00052     }
00053     else {
00054         return pow(x,_doublePower);
00055     }
00056 
00057 }
00058 
00059 
00060 
00061 Derivative Power::partial(unsigned int index) const {
00062   if (_asInteger) {
00063     const AbsFunction & fPrime = _intPower*Power(_intPower-1);
00064     return Derivative(&fPrime);
00065   }
00066   else {
00067     const AbsFunction & fPrime = _doublePower*Power(_doublePower-1);
00068     return Derivative(&fPrime);
00069   }
00070 
00071 }
00072 
00073 
00074 } // namespace Genfun

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7