Skip to content

Commit

Permalink
Again fixed ipow now it was a redeclaration.
Browse files Browse the repository at this point in the history
I now combined both versions into one, this makes it similar to what `pow` is.
However another version would be to put the enable if on the arguments, but I thought it would be too ugly.
  • Loading branch information
philip-paul-mueller committed Nov 12, 2024
1 parent def4d42 commit 28feda5
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions dace/runtime/include/dace/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,35 +576,26 @@ namespace dace
template<
typename T,
typename U,
typename = std::enable_if_t<(std::is_integral<U>::value && std::is_unsigned<U>::value)>
typename = std::enable_if_t<std::is_integral<U>::value>
>
DACE_CONSTEXPR DACE_HDFI T ipow(const T& a, const U b)
{
if(std::is_signed<U>::value) {
if(b < 0)
return 0;
}
if(b == 0) {
return T(1);
};
using IterationBound_t = std::make_unsigned_t<U>;
T result = a;
for (U i = 1; i < b; ++i)
const IterationBound_t stop{b};
for (IterationBound_t i = 1; i < stop; ++i)
result *= a;
return result;
}


template<
typename T,
typename U,
typename = std::enable_if_t<(std::is_integral<U>::value && std::is_signed<U>::value)>
>
DACE_CONSTEXPR DACE_HDFI T ipow(const T& a, const U b)
{
if(b < 0) {
return T(0);
};
using UnsignedU = std::make_unsigned_t<U>;
return ipow(a, UnsignedU{b});
}


template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
DACE_CONSTEXPR DACE_HDFI T ifloor(const T& a)
{
Expand Down

0 comments on commit 28feda5

Please sign in to comment.