aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilezhankin <ilezhankin@yandex-team.com>2023-06-30 11:11:35 +0300
committerilezhankin <ilezhankin@yandex-team.com>2023-06-30 11:11:35 +0300
commit5463eb3f5e72a86f858a3d27c886470a724ede34 (patch)
tree265403d37a83fd39e2f453191a346ae0aba56557
parentc132b4657d034ec319b4bb63f62a923adf9d7441 (diff)
downloadydb-5463eb3f5e72a86f858a3d27c886470a724ede34.tar.gz
Make CeilDiv function constexpr
-rw-r--r--util/generic/ymath.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/util/generic/ymath.h b/util/generic/ymath.h
index 4239143a66..6736c73d34 100644
--- a/util/generic/ymath.h
+++ b/util/generic/ymath.h
@@ -180,7 +180,7 @@ namespace NUtilMathPrivate {
template <>
struct TCeilDivImpl<true> {
template <class T>
- static inline T Do(T x, T y) noexcept {
+ static inline constexpr T Do(T x, T y) noexcept {
return x / y + (((x < 0) ^ (y > 0)) && (x % y));
}
};
@@ -188,7 +188,7 @@ namespace NUtilMathPrivate {
template <>
struct TCeilDivImpl<false> {
template <class T>
- static inline T Do(T x, T y) noexcept {
+ static inline constexpr T Do(T x, T y) noexcept {
auto quot = x / y;
return (x % y) ? (quot + 1) : quot;
}
@@ -199,7 +199,11 @@ namespace NUtilMathPrivate {
* @returns Equivalent to ceil((double) x / (double) y) but using only integer arithmetic operations
*/
template <class T>
-inline T CeilDiv(T x, T y) noexcept {
+inline T
+#if !defined(__NVCC__)
+ constexpr
+#endif
+ CeilDiv(T x, T y) noexcept {
static_assert(std::is_integral<T>::value, "Integral type required.");
Y_ASSERT(y != 0);
return ::NUtilMathPrivate::TCeilDivImpl<std::is_signed<T>::value>::Do(x, y);