Added support for negative powers in algo
This commit is contained in:
parent
c1f1cf5a38
commit
ada4626131
@ -12,6 +12,7 @@ int main(int argc, char **argv)
|
|||||||
cout << square(2.1f) << endl;
|
cout << square(2.1f) << endl;
|
||||||
cout << cube(2.1f) << endl;
|
cout << cube(2.1f) << endl;
|
||||||
|
|
||||||
|
cout << spower<-2>(2.1f) << endl;
|
||||||
cout << spower<2>(2.1f) << endl;
|
cout << spower<2>(2.1f) << endl;
|
||||||
cout << spower<3>(2.1f) << endl;
|
cout << spower<3>(2.1f) << endl;
|
||||||
cout << spower<4>(2.1f) << endl;
|
cout << spower<4>(2.1f) << endl;
|
||||||
|
@ -25,6 +25,10 @@ namespace CosmoTool
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
static T spower(T a)
|
static T spower(T a)
|
||||||
{
|
{
|
||||||
|
if (N<0)
|
||||||
|
{
|
||||||
|
return 1/SPowerBase<-N>::spower(a);
|
||||||
|
}
|
||||||
if ((N%2)==0)
|
if ((N%2)==0)
|
||||||
{
|
{
|
||||||
T b = SPowerBase<N/2>::spower(a);
|
T b = SPowerBase<N/2>::spower(a);
|
||||||
|
Loading…
Reference in New Issue
Block a user