projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
constexpr_pow
[folly.git]
/
folly
/
ConstexprMath.h
diff --git
a/folly/ConstexprMath.h
b/folly/ConstexprMath.h
index a15f098c5421b3d13168529ab1f7822276185b58..871b19433d6cc6f0ab89386b3f7f6cb5a65abec5 100644
(file)
--- a/
folly/ConstexprMath.h
+++ b/
folly/ConstexprMath.h
@@
-113,6
+113,11
@@
template <typename T>
constexpr T constexpr_log2_ceil_(T l2, T t) {
return l2 + T(T(1) << l2 < t ? 1 : 0);
}
constexpr T constexpr_log2_ceil_(T l2, T t) {
return l2 + T(T(1) << l2 < t ? 1 : 0);
}
+
+template <typename T>
+constexpr T constexpr_square_(T t) {
+ return t * t;
+}
} // namespace detail
template <typename T>
} // namespace detail
template <typename T>
@@
-132,4
+137,13
@@
constexpr T constexpr_ceil(T t, T round) {
: ((t + (t < T(0) ? T(0) : round - T(1))) / round) * round;
}
: ((t + (t < T(0) ? T(0) : round - T(1))) / round) * round;
}
+template <typename T>
+constexpr T constexpr_pow(T base, std::size_t exp) {
+ return exp == 0
+ ? T(1)
+ : exp == 1 ? base
+ : detail::constexpr_square_(constexpr_pow(base, exp / 2)) *
+ (exp % 2 ? base : T(1));
+}
+
} // namespace folly
} // namespace folly