diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (patch) | |
tree | cb7a9f4a92c0d4cc5a86eeed49ad71e810953c1f /util/generic/ymath.h | |
parent | 83a8efcf3af051e3dd59c00d1d5dafc96412ec1e (diff) | |
download | ydb-00afc96e9c0298054b7386fa7fb9e3cc3d67b974.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/ymath.h')
-rw-r--r-- | util/generic/ymath.h | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/util/generic/ymath.h b/util/generic/ymath.h index 9ff9ae2abe..4857b28566 100644 --- a/util/generic/ymath.h +++ b/util/generic/ymath.h @@ -172,35 +172,35 @@ inline bool FuzzyEquals(double p1, double p2, double eps = 1.0e-13) { inline bool FuzzyEquals(float p1, float p2, float eps = 1.0e-6) { return (Abs(p1 - p2) <= eps * Min(Abs(p1), Abs(p2))); } - -namespace NUtilMathPrivate { - template <bool IsSigned> - struct TCeilDivImpl {}; - - template <> - struct TCeilDivImpl<true> { + +namespace NUtilMathPrivate { + template <bool IsSigned> + struct TCeilDivImpl {}; + + template <> + struct TCeilDivImpl<true> { template <class T> - static inline T Do(T x, T y) noexcept { - return x / y + (((x < 0) ^ (y > 0)) && (x % y)); - } - }; - - template <> - struct TCeilDivImpl<false> { + static inline T Do(T x, T y) noexcept { + return x / y + (((x < 0) ^ (y > 0)) && (x % y)); + } + }; + + template <> + struct TCeilDivImpl<false> { template <class T> - static inline T Do(T x, T y) noexcept { - auto quot = x / y; - return (x % y) ? (quot + 1) : quot; - } - }; -} - -/** - * @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 { - 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); -} + static inline T Do(T x, T y) noexcept { + auto quot = x / y; + return (x % y) ? (quot + 1) : quot; + } + }; +} + +/** + * @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 { + 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); +} |