diff --git a/Tutorials/reduction/include/tmp_utils.hpp b/Tutorials/reduction/include/tmp_utils.hpp index 1c0507bd..7d1e6a6e 100644 --- a/Tutorials/reduction/include/tmp_utils.hpp +++ b/Tutorials/reduction/include/tmp_utils.hpp @@ -142,41 +142,19 @@ struct multiply return I * J; } }; -// Based on https://stackoverflow.com/a/63436491/1476661 by @jan-schultke + template struct divide_ceil { template FUNC_QUALIFIER constexpr int operator()() { - using Dividend = decltype(I); - using Divisor = decltype(J); - static constexpr auto x = I; - static constexpr auto y = J; - if constexpr(std::is_unsigned_v && std::is_unsigned_v) - { - // quotient is always positive - return x / y + (x % y != 0); // uint / uint - } - else if constexpr(std::is_signed_v && std::is_unsigned_v) - { - auto sy = static_cast>(y); - bool quotientPositive = x >= 0; - return x / sy + (x % sy != 0 && quotientPositive); // int / uint - } - else if constexpr(std::is_unsigned_v && std::is_signed_v) - { - auto sx = static_cast>(x); - bool quotientPositive = y >= 0; - return sx / y + (sx % y != 0 && quotientPositive); // uint / int - } - else - { - bool quotientPositive = (y >= 0) == (x >= 0); - return x / y + (x % y != 0 && quotientPositive); // int / int - } + static_assert(std::is_signed_v && std::is_signed_v, + "Invalid type."); + return (I + J - 1) / J; } }; + template struct select {