From 752d95c20e3639ab8ccc17dd9ba221ef74eec22d Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 18 Feb 2009 18:24:31 +0000 Subject: [PATCH] eventually c++ does not provide any optimized pow(int,int) function, so here you go :) (should also fix Timothy's troubles) --- Eigen/src/Core/MathFunctions.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 975f64e18..3bc8f4d5b 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -60,12 +60,20 @@ inline int ei_exp(int) { ei_assert(false); return 0; } inline int ei_log(int) { ei_assert(false); return 0; } inline int ei_sin(int) { ei_assert(false); return 0; } inline int ei_cos(int) { ei_assert(false); return 0; } - -#if EIGEN_GNUC_AT_LEAST(4,3) -inline int ei_pow(int x, int y) { return int(std::pow(x, y)); } -#else -inline int ei_pow(int x, int y) { return int(std::pow(double(x), y)); } -#endif +inline int ei_pow(int x, int y) +{ + int res = 1; + if(y < 0) return 0; + if(y & 1) res *= x; + y >>= 1; + while(y) + { + x *= x; + if(y&1) res *= x; + y >>= 1; + } + return res; +} template<> inline int ei_random(int a, int b) {