13 #if !defined(RANDOMLIB_MPFREXPONENTIALL_HPP)
14 #define RANDOMLIB_MPFREXPONENTIALL_HPP 1
19 #define HAVE_MPFR (MPFR_VERSION_MAJOR >= 3)
21 #if HAVE_MPFR || defined(DOXYGEN)
45 static const long chunk_ = 32;
53 mpfr_init2(_eps, chunk_);
54 mpfr_init2(_v1, chunk_);
55 mpfr_init2(_v2, chunk_);
75 int operator()(mpfr_t val, gmp_randstate_t r, mpfr_rnd_t round)
const {
77 mpfr_prec_t prec0 = mpfr_get_prec (val);
78 mpfr_prec_t prec = prec0 + 10;
79 mpz_urandomb(_vi, r, prec);
80 mpfr_set_ui_2exp(_eps, 1u, -prec, MPFR_RNDN);
81 mpfr_set_prec(_v1, prec);
82 mpfr_set_z_2exp(_v1, _vi, -prec, MPFR_RNDN);
83 mpfr_set_prec(_v2, prec);
84 mpfr_add(_v2, _v1, _eps, MPFR_RNDN);
86 int f2 = mpfr_log(val, _v2, round);
87 mpfr_set_prec(_v2, prec0);
88 int f1 = mpfr_log(_v2, _v1, round);
89 if (f1 == f2 && mpfr_equal_p(val, _v2)) {
90 mpfr_neg(val, val, MPFR_RNDN);
93 prec = Refine(r, prec);
101 mpfr_prec_t Refine(gmp_randstate_t r, mpfr_prec_t prec)
104 mpfr_div_2ui(_eps, _eps, chunk_, MPFR_RNDN);
105 mpz_urandomb(_vi, r, chunk_);
106 mpfr_set_prec(_v2, prec);
107 mpfr_set_z_2exp(_v2, _vi, -prec, MPFR_RNDN);
108 mpfr_add(_v2, _v1, _v2, MPFR_RNDN);
110 mpfr_set_prec(_v2, prec);
111 mpfr_add(_v2, _v1, _eps, MPFR_RNDN);
123 #endif // RANDOMLIB_MPFREXPONENTIALL_HPP
The exponential distribution for MPFR (the log method).
int operator()(mpfr_t val, gmp_randstate_t r, mpfr_rnd_t round) const