diff --git a/src/shrpx_connect_blocker.cc b/src/shrpx_connect_blocker.cc index 164dea86..4ffe29ca 100644 --- a/src/shrpx_connect_blocker.cc +++ b/src/shrpx_connect_blocker.cc @@ -80,8 +80,8 @@ void ConnectBlocker::on_failure() { ++fail_count_; - auto base_backoff = pow( - MULTIPLIER, static_cast(std::min(MAX_BACKOFF_EXP, fail_count_))); + auto base_backoff = + util::int_pow(MULTIPLIER, std::min(MAX_BACKOFF_EXP, fail_count_)); auto dist = std::uniform_real_distribution<>(-JITTER * base_backoff, JITTER * base_backoff); diff --git a/src/shrpx_live_check.cc b/src/shrpx_live_check.cc index ba0d150d..7f6559c8 100644 --- a/src/shrpx_live_check.cc +++ b/src/shrpx_live_check.cc @@ -157,8 +157,8 @@ constexpr auto JITTER = 0.2; } // namespace void LiveCheck::schedule() { - auto base_backoff = pow( - MULTIPLIER, static_cast(std::min(fail_count_, MAX_BACKOFF_EXP))); + auto base_backoff = + util::int_pow(MULTIPLIER, std::min(fail_count_, MAX_BACKOFF_EXP)); auto dist = std::uniform_real_distribution<>(-JITTER * base_backoff, JITTER * base_backoff); diff --git a/src/util.cc b/src/util.cc index 5a450bec..d24c5c8d 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1316,6 +1316,15 @@ StringRef percent_decode(BlockAllocator &balloc, const StringRef &src) { return StringRef{iov.base, p}; } +// Returns x**y +double int_pow(double x, size_t y) { + auto res = 1.; + for (; y; --y) { + res *= x; + } + return res; +} + } // namespace util } // namespace nghttp2 diff --git a/src/util.h b/src/util.h index 6d92529b..375dacfd 100644 --- a/src/util.h +++ b/src/util.h @@ -677,6 +677,9 @@ OutputIterator copy_lit(OutputIterator it, CharT(&s)[N]) { return std::copy_n(s, N - 1, it); } +// Returns x**y +double int_pow(double x, size_t y); + } // namespace util } // namespace nghttp2