From 883d1170e26306ca96738d1b664fc6a76b7c5836 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sun, 12 Sep 2010 10:33:51 +0200 Subject: [PATCH] Fixed use of pow --- src/octTree.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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;