cuda::ipow#
template <typename T, typename E>
[[nodiscard]] __host__ __device__ inline constexpr
T ipow(T base, E exp) noexcept;
The function computes the integer base raised to the power of exp.
Parameters
base: The base value.exp: The exponent value.
Return value
The result of raising
baseto the power ofexp. Ifexpis negative, the result is 0.
Constraints
Tis an integer type.Eis an integer type.
Preconditions
if
baseis 0, thenexpmust be non-negative.
Example#
#include <cuda/cmath>
#include <cuda/std/cassert>
__global__ void ipow_kernel() {
assert(cuda::ipow(0, 0) == 1);
assert(cuda::ipow(2, 2) == 4);
assert(cuda::ipow(99, 1) == 99);
assert(cuda::ipow(4, 7) == 16384);
assert(cuda::ipow(-1, 3) == -1);
assert(cuda::ipow(23, -1) == 0);
}
int main() {
ipow_kernel<<<1, 1>>>();
cudaDeviceSynchronize();
}