aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/ymath.h
diff options
context:
space:
mode:
authorAndrey Khalyavin <halyavin@gmail.com>2022-02-10 16:46:30 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:30 +0300
commit4b839d0704ee9be1dabb0310a1f03af24963637b (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/generic/ymath.h
parentf773626848a7c7456803654292e716b83d69cc12 (diff)
downloadydb-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.h52
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.