diff options
author | Andrey Khalyavin <halyavin@gmail.com> | 2022-02-10 16:46:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:30 +0300 |
commit | 4b839d0704ee9be1dabb0310a1f03af24963637b (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/generic/ymath.h | |
parent | f773626848a7c7456803654292e716b83d69cc12 (diff) | |
download | ydb-4b839d0704ee9be1dabb0310a1f03af24963637b.tar.gz |
Restoring authorship annotation for Andrey Khalyavin <halyavin@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util/generic/ymath.h')
-rw-r--r-- | util/generic/ymath.h | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/util/generic/ymath.h b/util/generic/ymath.h index 0614b1d080..9ff9ae2abe 100644 --- a/util/generic/ymath.h +++ b/util/generic/ymath.h @@ -1,6 +1,6 @@ #pragma once -#include <util/system/yassert.h> +#include <util/system/yassert.h> #include <util/system/defaults.h> #include <cmath> @@ -120,32 +120,32 @@ inline double LogGamma(double x) noexcept { return LogGammaImpl(x); #endif } - -/** - * @returns x^n for integer n, n >= 0. - */ + +/** + * @returns x^n for integer n, n >= 0. + */ template <class T, class Int> -T Power(T x, Int n) { - static_assert(std::is_integral<Int>::value, "only integer powers are supported"); - Y_ASSERT(n >= 0); - if (n == 0) { - return T(1); - } - while ((n & 1) == 0) { - x = x * x; - n >>= 1; - } - T result = x; - n >>= 1; - while (n > 0) { - x = x * x; - if (n & 1) { - result = result * x; - } - n >>= 1; - } - return result; -}; +T Power(T x, Int n) { + static_assert(std::is_integral<Int>::value, "only integer powers are supported"); + Y_ASSERT(n >= 0); + if (n == 0) { + return T(1); + } + while ((n & 1) == 0) { + x = x * x; + n >>= 1; + } + T result = x; + n >>= 1; + while (n > 0) { + x = x * x; + if (n & 1) { + result = result * x; + } + n >>= 1; + } + return result; +}; /** * Compares two floating point values and returns true if they are considered equal. |