StatMech
Loading...
Searching...
No Matches
powi.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifndef __NVCC__
4# define __host__
5# define __device__
6#endif
7
8template<typename Integer1, typename Integer2>
9static inline __host__ __device__ Integer1 powi(Integer1 base, Integer2 exponent) {
10 if(exponent == 0) return 1;
11 if(exponent == 1) return base;
12
13 Integer1 temp = powi(base, exponent / 2);
14 if(exponent % 2 == 0) return temp * temp;
15 else return base * temp * temp;
16}