mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-25 22:34:30 +08:00
eventually c++ does not provide any optimized pow(int,int) function,
so here you go :) (should also fix Timothy's troubles)
This commit is contained in:
parent
747d83a05a
commit
752d95c20e
@ -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_log(int) { ei_assert(false); return 0; }
|
||||||
inline int ei_sin(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; }
|
inline int ei_cos(int) { ei_assert(false); return 0; }
|
||||||
|
inline int ei_pow(int x, int y)
|
||||||
#if EIGEN_GNUC_AT_LEAST(4,3)
|
{
|
||||||
inline int ei_pow(int x, int y) { return int(std::pow(x, y)); }
|
int res = 1;
|
||||||
#else
|
if(y < 0) return 0;
|
||||||
inline int ei_pow(int x, int y) { return int(std::pow(double(x), y)); }
|
if(y & 1) res *= x;
|
||||||
#endif
|
y >>= 1;
|
||||||
|
while(y)
|
||||||
|
{
|
||||||
|
x *= x;
|
||||||
|
if(y&1) res *= x;
|
||||||
|
y >>= 1;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
template<> inline int ei_random(int a, int b)
|
template<> inline int ei_random(int a, int b)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user