Keith H Duggar wrote:

> I suspect your "integer pow" just iterates to do the exponentiation.

No, I actually used compile time recursion.

Really? How interesting, can you please post the code for

the function?

Keith

This is based on ideas from _C++_Templates_ The_Complet_Gui de_

http://www.josuttis.com/tmplbook/
I really don't know if this has any advantages, nor do I know if it is even

correct. I ran it through a few simple tests, but haven't revisited it

since. As I am working on my testing infrastructure.

/*************** *************** *************** *************** ***************

* Copyright (C) 2004 by Steven T. Hatton *

*

ha*****@globals ymmetry.com *

* *

* This program is free software; you can redistribute it and/or modify *

* it under the terms of the GNU General Public License as published by *

* the Free Software Foundation; either version 2 of the License, or *

* (at your option) any later version. *

* *

* This program is distributed in the hope that it will be useful, *

* but WITHOUT ANY WARRANTY; without even the implied warranty of *

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *

* GNU General Public License for more details. *

* *

* You should have received a copy of the GNU General Public License *

* along with this program; if not, write to the *

* Free Software Foundation, Inc., *

* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *

*************** *************** *************** *************** ***************/

#ifndef STH_TMATHPOWER_ H

#define STH_TMATHPOWER_ H

#include<stdexc ept>

namespace sth {

namespace tmath {

/**

@author Steven T. Hatton

*/

template <size_t Exponent_S, typename T>

class PowerOf

{

public:

static T eval(const T& base)

{

return base * PowerOf<Exponen t_S - 1, T>::eval(base) ;

}

};

template <typename T>

class PowerOf<1, T>

{

public:

static T eval(const T& base)

{

return base;

}

};

template <typename T>

class PowerOf<0, T>

{

public:

static T eval(const T& base)

{

if(!base)

{

throw std::logic_erro r(

"sth::tmath::Po werOf<0>(0) is an indeterminate form.");

}

return 1;

}

};

template <size_t Exponent_S, typename T>

T power(const T& base)

{

return PowerOf<Exponen t_S, T>::eval(base) ;

}

};

}

#endif

--

"If our hypothesis is about anything and not about some one or more

particular things, then our deductions constitute mathematics. Thus

mathematics may be defined as the subject in which we never know what we

are talking about, nor whether what we are saying is true." - Bertrand

Russell