ExRandom  3.0
MPFR functions
Back to Multi-precision floating-point types. Forward to Other examples. Up to Contents.

Algorithms N and V have been added to MPFR version 4.0.1 (2018-02-08).

The added functions are

  • mpfr_nrandom (rop, state, rnd_mode) – Generate a normal deviate with mean 0 and variance 1 and round it to the precision of rop according to the given rounding mode.
  • mpfr_erandom (rop, state, rnd_mode) – Generate an exponential deviate with mean 1 and round it to the precision of rop according to the given rounding mode.

These are considerably more efficient than unit_normal_distribution and unit_exponential_distribution with an MPFR floating-point type particular when the precision is large. Because these routines write directly into the memory for a mpfr_t, the CPU time is proportional to the precision. In contrast, u_rand, in order to allow the use of a wide range of floating point types, generates high precision floating point numbers using a sequence of arithmetic operations whose cost scales as the square of the precision.

The program mpfr_times.cpp compares the time for mpfr_nrandom with mpfr_grandom, an implementation of polar method for normal sampling which appeared in MPFR 3.1. This (with tx multiplied by 10) is used to generate the timing data in Table 2, columns C and D, of the paper. Also compared is the time for unit_normal_distribution<mpfr::mpreal>.

Back to Multi-precision floating-point types. Forward to Other examples. Up to Contents.