CLHEP VERSION 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     : AbsFunction(right),
00026       _doublePower(right._doublePower),
00027       _intPower(right._intPower),
00028       _asInteger(right._asInteger)
00029 {}
00030 
00031 Power::~Power() {
00032 }
00033 
00034 double Power::operator() (double x) const {
00035     if (_asInteger) {
00036         if (_intPower==0) {
00037             return 1;
00038         }
00039         else if (_intPower>0) {
00040             double f = 1;
00041             for (int i=0;i<_intPower;i++) {
00042                 f *=x;
00043             }
00044             return f;
00045         }
00046         else {
00047             double f = 1;
00048             for (int i=0;i<-_intPower;i++) {
00049                 f /=x;
00050             }
00051             return f;
00052         }           
00053     }
00054     else {
00055         return std::pow(x,_doublePower);
00056     }
00057 
00058 }
00059 
00060 
00061 
00062 Derivative Power::partial(unsigned int) const {
00063   if (_asInteger) {
00064     const AbsFunction & fPrime = _intPower*Power(_intPower-1);
00065     return Derivative(&fPrime);
00066   }
00067   else {
00068     const AbsFunction & fPrime = _doublePower*Power(_doublePower-1);
00069     return Derivative(&fPrime);
00070   }
00071 
00072 }
00073 
00074 
00075 } // namespace Genfun

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7