If we want to compute
It can be easily implemented in C/C++ that includes the math.h:
inline
double power(double x, double y) {
return exp(y * log(x));
}
This article just gives you the quick implementation if you just want to know roughly the value of
How is it compared to the pow() function in C/C++? Is it faster? Is it numerically stable? We have to run some tests before coming to a conclusion. The implementation of pow() may look like this:
double pow(double x, double y) {
if (abs((int)y - y) < EPS) { // if y is integer
return power(x, (int)y) ; // speed up if y is integer
}
if (y < 0) {
return 1.0 / power(x, -y); // e.g. 2^(-1) = 1.0/(2^1)
}
return power(x, y); // use the above implementation :)
}
--EOF (The Ultimate Computing & Technology Blog) --
Last Post: How to Read File Content from URL with Time out in PHP?
Next Post: How to Compute Minkowski, Euclidean and CityBlock Distance in C++?