Commit e5067964 by Derek Mauro Committed by Copybara-Service

Fix an implicit truncation warning under MSVC 32-bit

Since the return value of `NumBits()` will always fit into `size_t`,
use an explicit cast to silence the implicit conversion warning.

Fixes #1384

PiperOrigin-RevId: 518041598
Change-Id: If2f2456db4b27b78e9ea9e026dce610953bd5bfb
parent f959f6ba
......@@ -57,9 +57,10 @@ constexpr UIntType IntegerLog2(UIntType n) {
// `PowerOfTwoVariate(urbg)`.
template <typename URBG>
constexpr size_t NumBits() {
return RangeSize<URBG>() == 0
return static_cast<size_t>(
RangeSize<URBG>() == 0
? std::numeric_limits<typename URBG::result_type>::digits
: IntegerLog2(RangeSize<URBG>());
: IntegerLog2(RangeSize<URBG>()));
}
// Given a shift value `n`, constructs a mask with exactly the low `n` bits set.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment