Go to the documentation of this file.
15 #ifndef ABSL_RANDOM_GAUSSIAN_DISTRIBUTION_H_
16 #define ABSL_RANDOM_GAUSSIAN_DISTRIBUTION_H_
29 #include <type_traits>
31 #include "absl/base/config.h"
32 #include "absl/random/internal/fast_uniform_bits.h"
33 #include "absl/random/internal/generate_real.h"
34 #include "absl/random/internal/iostream_state_saver.h"
38 namespace random_internal {
49 template <
typename URBG>
50 inline double zignor(URBG&
g);
55 template <
typename URBG>
56 inline double zignor_fallback(URBG&
g,
60 static constexpr
double kR = 3.442619855899;
61 static constexpr
double kRInv = 0.29047645161474317;
62 static constexpr
double kV = 9.91256303526217e-3;
86 template <
typename RealType =
double>
106 return a.mean_ ==
b.mean_ &&
a.stddev_ ==
b.stddev_;
119 "Class-template absl::gaussian_distribution<> must be parameterized "
120 "using a floating-point type.");
133 template <
typename URBG>
138 template <
typename URBG>
140 const param_type& p);
146 return -std::numeric_limits<result_type>::infinity();
149 return std::numeric_limits<result_type>::infinity();
157 return a.param_ ==
b.param_;
161 return a.param_ !=
b.param_;
172 template <
typename RealType>
173 template <
typename URBG>
178 return p.mean() + p.stddev() *
static_cast<result_type>(zignor(
g));
181 template <
typename CharT,
typename Traits,
typename RealType>
183 std::basic_ostream<CharT, Traits>& os,
187 os <<
x.mean() << os.fill() <<
x.stddev();
191 template <
typename CharT,
typename Traits,
typename RealType>
193 std::basic_istream<CharT, Traits>& is,
199 auto mean = random_internal::read_floating_point<result_type>(is);
200 if (is.fail())
return is;
201 auto stddev = random_internal::read_floating_point<result_type>(is);
203 x.param(param_type(mean, stddev));
208 namespace random_internal {
210 template <
typename URBG>
220 std::log(GenerateRealFromBits<double, GeneratePositiveTag, false>(
223 GenerateRealFromBits<double, GeneratePositiveTag, false>(
fast_u64_(
g)));
224 }
while ((
y +
y) < (
x *
x));
225 return neg ? (
x -
kR) : (
kR -
x);
228 template <
typename URBG>
242 double j = GenerateRealFromBits<double, GenerateSignedTag, false>(
244 const double x = j *
zg_.
x[
i];
249 if (std::abs(
x) <
zg_.
x[
i + 1]) {
260 double v = GenerateRealFromBits<double, GeneratePositiveTag, false>(
263 std::exp(-0.5 *
x *
x)) {
275 #endif // ABSL_RANDOM_GAUSSIAN_DISTRIBUTION_H_
result_type operator()(URBG &g)
istream_state_saver< std::basic_istream< CharT, Traits > > make_istream_state_saver(std::basic_istream< CharT, Traits > &is, std::ios_base::fmtflags flags=std::ios_base::dec|std::ios_base::scientific|std::ios_base::skipws)
result_type stddev() const
ABSL_NAMESPACE_BEGIN std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
result_type() min() const
static constexpr double kR
friend bool operator!=(const gaussian_distribution &a, const gaussian_distribution &b)
static constexpr double kRInv
void param(const param_type &p)
result_type stddev() const
#define ABSL_NAMESPACE_END
RealType GenerateRealFromBits(uint64_t bits, int exp_bias=0)
#define ABSL_NAMESPACE_BEGIN
const typedef int * result_type
unsigned __int64 uint64_t
OPENSSL_EXPORT ASN1_BIT_STRING * bits
friend bool operator!=(const param_type &a, const param_type &b)
random_internal::FastUniformBits< uint64_t > fast_u64_
gaussian_distribution(const param_type &p)
param_type(result_type mean=0, result_type stddev=1)
constexpr uint128 operator>>(uint128 lhs, int amount)
friend bool operator==(const param_type &a, const param_type &b)
gaussian_distribution(result_type mean, result_type stddev=1)
static constexpr uint64_t kMask
result_type() max() const
ostream_state_saver< std::basic_ostream< CharT, Traits > > make_ostream_state_saver(std::basic_ostream< CharT, Traits > &os, std::ios_base::fmtflags flags=std::ios_base::dec|std::ios_base::left|std::ios_base::scientific)
friend bool operator==(const gaussian_distribution &a, const gaussian_distribution &b)
double zignor_fallback(URBG &g, bool neg)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:25