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
base
to the power ofexp
. Ifexp
is negative, the result is 0.
Constraints
T
is an integer type.E
is an integer type.
Preconditions
if
base
is 0, thenexp
must 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();
}