1 /////////////////////////////////////////////////////////////////////////// 2 // Inastemp - Berenger Bramas MPCDF - 2016 3 // Under MIT Licence, please you must read the LICENCE file. 4 /////////////////////////////////////////////////////////////////////////// 5 #ifndef UTILS_HPP 6 #define UTILS_HPP 7 8 // for std::size_t 9 #include <cstdio> 10 11 namespace InaUtils { 12 13 template < class TypeSrc, class TypeDest > ConvertBits(TypeSrc src)14inline TypeDest ConvertBits(TypeSrc src) { 15 union InaBits { 16 TypeSrc src; 17 TypeDest dest; 18 }; 19 InaBits bits; 20 bits.src = src; 21 return bits.dest; 22 } 23 24 template <class VecType> FastPow(VecType base,std::size_t power)25inline VecType FastPow(VecType base, std::size_t power){ 26 VecType res = VecType(1.); 27 28 while(power){ 29 if(1 & power){ 30 res *= base; 31 } 32 base *= base; 33 power >>= 1; 34 } 35 36 return res; 37 } 38 FastPowNbMul(std::size_t power)39inline std::size_t FastPowNbMul(std::size_t power){ 40 std::size_t nbMul = 0; 41 42 while(power){ 43 if(1 & power){ 44 nbMul += 1; 45 } 46 nbMul += 1; 47 power >>= 1; 48 } 49 50 return nbMul; 51 } 52 53 } 54 55 #endif // UTILS_HPP 56