diff --git a/src/octTree.cpp b/src/octTree.cpp index a56e281..4ef929d 100644 --- a/src/octTree.cpp +++ b/src/octTree.cpp @@ -9,12 +9,27 @@ using namespace CosmoTool; //#define VERBOSE +static uint32_t mypow(uint32_t i, uint32_t p) +{ + if (p == 0) + return 1; + else if (p == 1) + return i; + + uint32_t k = p/2; + uint32_t j = mypow(i, k); + if (2*k==p) + return j*j; + else + return j*j*i; +} + OctTree::OctTree(const FCoordinates *particles, octPtr numParticles, uint32_t maxMeanTreeDepth, uint32_t maxAbsoluteDepth, uint32_t threshold) { cout << "MeanTree=" << maxMeanTreeDepth << endl; - numCells = pow(8, maxMeanTreeDepth); + numCells = mypow(8, maxMeanTreeDepth); assert(numCells < invalidOctCell); //#ifdef VERBOSE cerr << "Allocating " << numCells << " octtree cells" << endl;