diff --git a/folly/ConstexprMath.h b/folly/ConstexprMath.h index 533cb1a277b..d4115963de8 100644 --- a/folly/ConstexprMath.h +++ b/folly/ConstexprMath.h @@ -459,7 +459,10 @@ constexpr T constexpr_mult(T const a, T const b) { namespace detail { -template +template < + typename T, + typename E, + std::enable_if_t::value, int> = 1> constexpr T constexpr_ipow(T const base, E const exp) { if (std::is_floating_point::value) { if (exp < E(0)) { @@ -485,6 +488,31 @@ constexpr T constexpr_ipow(T const base, E const exp) { return constexpr_mult(constexpr_mult(div, div), rem); } +template < + typename T, + typename E, + std::enable_if_t::value, int> = 1> +constexpr T constexpr_ipow(T const base, E const exp) { + if (std::is_floating_point::value) { + if (exp == E(0)) { + return T(1); + } + if (constexpr_isnan(base)) { + return base; + } + } + if (exp == E(0)) { + return T(1); + } + if (exp == E(1)) { + return base; + } + auto const hexp = constexpr_trunc(exp / E(2)); + auto const div = constexpr_ipow(base, hexp); + auto const rem = hexp * E(2) == exp ? T(1) : base; + return constexpr_mult(constexpr_mult(div, div), rem); +} + } // namespace detail /// constexpr_exp diff --git a/folly/concurrency/CacheLocality.cpp b/folly/concurrency/CacheLocality.cpp index 2ea8c2dffc2..b73a87e3034 100644 --- a/folly/concurrency/CacheLocality.cpp +++ b/folly/concurrency/CacheLocality.cpp @@ -467,7 +467,8 @@ class SimpleAllocator { // leave pointers that could hide leaks at shutdown, since the backing // slabs may not be deallocated if the instance is a leaky singleton. auto* base = static_cast(ptr); - std::fill(base + sizeof(void*), base + allocator->sz_, 0); + std::fill( + base + sizeof(void*), base + allocator->sz_, static_cast(0)); } allocator->freelist_ = ptr; } diff --git a/folly/hash/Hash.h b/folly/hash/Hash.h index 0fd342b2ed7..7000f3d6530 100644 --- a/folly/hash/Hash.h +++ b/folly/hash/Hash.h @@ -528,7 +528,7 @@ struct integral_hasher { auto const u = to_unsigned(i); auto const hi = static_cast(u >> sizeof(Int) * 4); auto const lo = static_cast(u); - return hash::hash_128_to_64(hi, lo); + return static_cast(hash::hash_128_to_64(hi, lo)); } } };