Skip to content

Commit

Permalink
Restrict utilities to integer types (#2264)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard authored May 6, 2024
1 parent 850995c commit 540beba
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions include/alpaka/core/Utility.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Benjamin Worpitz, René Widera, Bernhard Manfred Gruber, Jan Stephan
/* Copyright 2024 Benjamin Worpitz, René Widera, Bernhard Manfred Gruber, Jan Stephan, Andrea Bocci
* SPDX-License-Identifier: MPL-2.0
*/
#pragma once
Expand All @@ -23,14 +23,14 @@ namespace alpaka::core
#endif

/// Returns the ceiling of a / b, as integer.
template<typename Integral>
template<typename Integral, typename = std::enable_if_t<std::is_integral_v<Integral>>>
[[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto divCeil(Integral a, Integral b) -> Integral
{
return (a + b - 1) / b;
}

/// Computes the nth power of base, in integers.
template<typename Integral>
template<typename Integral, typename = std::enable_if_t<std::is_integral_v<Integral>>>
[[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto intPow(Integral base, Integral n) -> Integral
{
if(n == 0)
Expand All @@ -42,7 +42,7 @@ namespace alpaka::core
}

/// Computes the floor of the nth root of value, in integers.
template<typename Integral>
template<typename Integral, typename = std::enable_if_t<std::is_integral_v<Integral>>>
[[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto nthRootFloor(Integral value, Integral n) -> Integral
{
// adapted from: https://en.wikipedia.org/wiki/Integer_square_root
Expand All @@ -58,4 +58,5 @@ namespace alpaka::core
}
return L;
}

} // namespace alpaka::core

0 comments on commit 540beba

Please sign in to comment.