/usr/include/opengm/utilities/unsigned_integer_pow.hxx is in libopengm-dev 2.3.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #ifndef OPENGM_UNSIGNED_INTEGER_POW_HXX_
#define OPENGM_UNSIGNED_INTEGER_POW_HXX_
namespace opengm {
size_t unsignedIntegerPow(size_t base, size_t exponent) {
if(base == 1) {
return 1;
} else if((base == 0) && (exponent > 0)) {
return 0;
} else {
// exponentiation by squaring
size_t result = 1;
while(exponent) {
// check if exponent is odd
if(exponent % 2 == 1) {
result *= base;
}
// halve exponent
exponent /= 2;
// square base
base *= base;
}
return result;
}
}
} // namespace opengm
/*! \file unsigned_integer_pow.hxx
* \brief Provides implementation for the power function of unsigned integer
* values.
*/
/*! \fn size_t opengm::unsignedIntegerPow(size_t base, size_t exponent)
* \brief Unsigned integer power function.
*
* \param[in] base The base for the power function computation.
* \param[in] exponent The exponent for the power function computation.
*
* \return Returns the value of the power function base^exponent.
*
* \warning Might overflow for even small values of base and exponent due to
* the limited capacities of size_t.
*/
#endif /* OPENGM_UNSIGNED_INTEGER_POW_HXX_ */
|