summaryrefslogtreecommitdiff
path: root/absl/random/exponential_distribution.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/random/exponential_distribution.h')
-rw-r--r--absl/random/exponential_distribution.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/absl/random/exponential_distribution.h b/absl/random/exponential_distribution.h
index ed5551ae..b5caf8a1 100644
--- a/absl/random/exponential_distribution.h
+++ b/absl/random/exponential_distribution.h
@@ -21,12 +21,13 @@
#include <limits>
#include <type_traits>
-#include "absl/random/internal/distribution_impl.h"
+#include "absl/meta/type_traits.h"
#include "absl/random/internal/fast_uniform_bits.h"
+#include "absl/random/internal/generate_real.h"
#include "absl/random/internal/iostream_state_saver.h"
namespace absl {
-inline namespace lts_2019_08_08 {
+ABSL_NAMESPACE_BEGIN
// absl::exponential_distribution:
// Generates a number conforming to an exponential distribution and is
@@ -119,9 +120,14 @@ typename exponential_distribution<RealType>::result_type
exponential_distribution<RealType>::operator()(
URBG& g, // NOLINT(runtime/references)
const param_type& p) {
- using random_internal::NegativeValueT;
- const result_type u = random_internal::RandU64ToReal<
- result_type>::template Value<NegativeValueT, false>(fast_u64_(g));
+ using random_internal::GenerateNegativeTag;
+ using random_internal::GenerateRealFromBits;
+ using real_type =
+ absl::conditional_t<std::is_same<RealType, float>::value, float, double>;
+
+ const result_type u = GenerateRealFromBits<real_type, GenerateNegativeTag,
+ false>(fast_u64_(g)); // U(-1, 0)
+
// log1p(-x) is mathematically equivalent to log(1 - x) but has more
// accuracy for x near zero.
return p.neg_inv_lambda_ * std::log1p(u);
@@ -153,7 +159,7 @@ std::basic_istream<CharT, Traits>& operator>>(
return is;
}
-} // inline namespace lts_2019_08_08
+ABSL_NAMESPACE_END
} // namespace absl
#endif // ABSL_RANDOM_EXPONENTIAL_DISTRIBUTION_H_