Added support for negative powers in algo

This commit is contained in:
Your Name 2012-06-05 16:41:55 -04:00
parent c1f1cf5a38
commit ada4626131
2 changed files with 5 additions and 0 deletions

View File

@ -12,6 +12,7 @@ int main(int argc, char **argv)
cout << square(2.1f) << endl;
cout << cube(2.1f) << endl;
cout << spower<-2>(2.1f) << endl;
cout << spower<2>(2.1f) << endl;
cout << spower<3>(2.1f) << endl;
cout << spower<4>(2.1f) << endl;

View File

@ -25,6 +25,10 @@ namespace CosmoTool
template<typename T>
static T spower(T a)
{
if (N<0)
{
return 1/SPowerBase<-N>::spower(a);
}
if ((N%2)==0)
{
T b = SPowerBase<N/2>::spower(a);