Commit 1efc3cff authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #3124 from f-morozov:optim_pr

parents 552bda92 0ae89fe2
......@@ -74,4 +74,24 @@ inline int fRound(float flt) {
return (int)(flt + 0.5f);
}
/* ************************************************************************* */
/**
* @brief Exponentiation by squaring
* @param flt Exponentiation base
* @return dst Exponentiation value
*/
inline int fastpow(int base, int exp) {
int res = 1;
while(exp > 0) {
if(exp & 1) {
exp--;
res *= base;
} else {
exp /= 2;
base *= base;
}
}
return res;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment