10 #if !defined(EXRANDOM_UNIT_NORMAL_KAHN_HPP) 11 #define EXRANDOM_UNIT_NORMAL_KAHN_HPP 1 54 template<
typename Generator>
59 std::pair<long long, long long> px = x.
rational();
60 std::pair<long long, long long> py = _y.rational();
62 long long nxl = px.first, dx = px.second;
64 if (nxl < 0LL) nxl = -nxl-1;
65 long long nxu = nxl + 1;
66 nxl *= nxl; nxu *= nxu; dx *= dx;
67 long long nyl = py.first, nyu = nyl + 1, dy = py.second;
74 if (!(dx > 0 && dy > 0))
81 nxl *= dy/dx; nxu *= dy/dx;
83 nyl *= dx/dy; nyu *= dx/dy;
85 if (!(nxl >= 0 && nxu > nxl && nyl >= 0 && nyu > nyl))
92 if (_y.init().less_than_half(g)) x.
negate();
99 if (nxu - nxl >= nyu - nyl)
102 py = _y.rational(g, _y.ndigits() + 1);
115 template<
typename RealType,
typename Generator>
118 return _x.template value<RealType>(g);
133 template<
typename RealType,
typename Generator>
136 return _x.template midpoint<RealType>(g, k);
147 static const uint_t
base = digit_gen::base;
149 static const int bits = digit_gen::bits;
150 static const bool power_of_two = digit_gen::power_of_two;
152 static_assert(
base &&
base <= 16,
"base must not be greater than 16");
163 #endif // EXRANDOM_UNIT_NORMAL_KAHN_HPP Sample u-rands from the normal distribution, Kahn's method (deprecated)
void generate(Generator &g, u_rand< digit_gen > &x)
std::pair< long long, long long > rational() const
RealType value(Generator &g)
RealType midpoint(Generator &g, size_t k)
digit_gen & digit_generator() const
unit_normal_kahn(digit_gen &D)
Definition of unit_exponential_dist.
The machinery to handle u-rands, arbitrary precision random deviates.
void generate(Generator &g, u_rand< digit_gen > &x)