12 #if !defined(RANDOMLIB_MPFRNORMALK_HPP)
13 #define RANDOMLIB_MPFRNORMALK_HPP 1
19 #if HAVE_MPFR || defined(DOXYGEN)
50 { mpfr_init2(_xf, MPFR_PREC_MIN); mpfr_init2(_zf, MPFR_PREC_MIN); }
55 { mpfr_clear(_zf); mpfr_clear(_xf); }
64 { Compute(r); _x.swap(t); }
74 int operator()(mpfr_t val, gmp_randstate_t r, mpfr_rnd_t round)
const
75 { Compute(r);
return _x(val, r, round); }
80 void Compute(gmp_randstate_t r)
const {
87 for (mp_size_t k = 1; ; ++k) {
88 _x.ExpandTo(r, k - 1);
89 _z.ExpandTo(r, k - 1);
90 mpfr_prec_t prec = (std::max)(mpfr_prec_t(MPFR_PREC_MIN), k * bits);
91 mpfr_set_prec(_xf, prec);
92 mpfr_set_prec(_zf, prec);
95 if (_x.UInteger() == 0) {
97 mpfr_ui_sub(_xf, 1u, _xf, MPFR_RNDU);
100 mpfr_sub_ui(_xf, _xf, 1u, MPFR_RNDU);
102 mpfr_sqr(_xf, _xf, MPFR_RNDU);
104 mpfr_mul_2ui(_zf, _zf, 1u, MPFR_RNDD);
105 if (mpfr_cmp(_xf, _zf) < 0) {
106 if (_x.Boolean(r)) _x.Negate();
111 if (_x.UInteger() == 0) {
113 mpfr_ui_sub(_xf, 1u, _xf, MPFR_RNDD);
116 mpfr_sub_ui(_xf, _xf, 1u, MPFR_RNDD);
118 mpfr_sqr(_xf, _xf, MPFR_RNDD);
120 mpfr_mul_2ui(_zf, _zf, 1u, MPFR_RNDU);
121 if (mpfr_cmp(_xf, _zf) > 0)
128 mutable MPFRRandom<bits> _x;
129 mutable MPFRRandom<bits> _z;
132 const MPFRExponential<bits> _edist;
138 #endif // RANDOMLIB_MPFRNORMALK_HPP
The normal distribution for MPFR (Kahn algorithm).
Header for MPFRExponential.
void operator()(MPFRRandom< bits > &t, gmp_randstate_t r) const
Handling random numbers in MPFR.
int operator()(mpfr_t val, gmp_randstate_t r, mpfr_rnd_t round) const