Skip to content
Snippets Groups Projects
Commit 71bc06bd authored by Matthias Steinke's avatar Matthias Steinke
Browse files

added two more integer pow functions to MathUtils.hh

parent 11f7eae1
No related branches found
No related tags found
No related merge requests found
#ifndef MATHUTILS_HH
#define MATHUTILS_HH
#include <cassert>
inline double pow(double x, int p)
{
if(p == 0) return 1.0;
if(x == 0.0 && p > 0) return 0.0;
if(p < 0) {p=-p; x=1/x;}
double r = 1.0;
for(;;) {
if(p & 1) r *= x;
if((p >>= 1) == 0) return r;
x *= x;
}
}
inline double pow(double x, unsigned int p)
{
if(p == 0) return 1.0;
if(x == 0.0) return 0.0;
double r = 1.0;
for(;;) {
if(p & 1) r *= x;
if((p >>= 1) == 0) return r;
x *= x;
}
}
inline int pow(int x, int p)
{
if(p == 0) return 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment