diff options
Diffstat (limited to 'absl/random/log_uniform_int_distribution.h')
-rw-r--r-- | absl/random/log_uniform_int_distribution.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/absl/random/log_uniform_int_distribution.h b/absl/random/log_uniform_int_distribution.h index 960816e2..43e10116 100644 --- a/absl/random/log_uniform_int_distribution.h +++ b/absl/random/log_uniform_int_distribution.h @@ -23,6 +23,7 @@ #include <ostream> #include <type_traits> +#include "absl/numeric/bits.h" #include "absl/random/internal/fastmath.h" #include "absl/random/internal/generate_real.h" #include "absl/random/internal/iostream_state_saver.h" @@ -68,8 +69,10 @@ class log_uniform_int_distribution { if (base_ == 2) { // Determine where the first set bit is on range(), giving a log2(range) // value which can be used to construct bounds. - log_range_ = (std::min)(random_internal::LeadingSetBit(range()), - std::numeric_limits<unsigned_type>::digits); + log_range_ = + (std::min)(bit_width(range()), + static_cast<unsigned_type>( + std::numeric_limits<unsigned_type>::digits)); } else { // NOTE: Computing the logN(x) introduces error from 2 sources: // 1. Conversion of int to double loses precision for values >= |