RandomLib
1.10
|
Handling random numbers in MPFR. More...
#include <RandomLib/MPFRRandom.hpp>
Public Member Functions | |
MPFRRandom () | |
MPFRRandom (const MPFRRandom &t) | |
~MPFRRandom () | |
MPFRRandom & | operator= (const MPFRRandom &t) |
void | swap (MPFRRandom &t) throw () |
void | Init () |
int | Sign () const throw () |
void | Negate () throw () |
long | Floor () const throw () |
long | Ceiling () const throw () |
unsigned long | UInteger () const throw () |
unsigned long | Size () const throw () |
void | AddInteger (long k) |
int | LessThan (gmp_randstate_t r, MPFRRandom &t) |
void | SetHighBit (gmp_randstate_t r) |
int | TestHighBit (gmp_randstate_t r) |
mp_size_t | LeadingBit (gmp_randstate_t r) |
void | ExpandTo (gmp_randstate_t r, mp_size_t k) |
int | operator() (mpfr_t val, mpfr_rnd_t round) |
int | operator() (mpfr_t val, gmp_randstate_t r, mpfr_rnd_t round) |
int | Boolean (gmp_randstate_t r) const |
Handling random numbers in MPFR.
This class provides roughly the same capabilities as RandomNumber. The fraction is represented by a mpz integer f and an exponent e. We have e ≥ 0 and 0 ≤ f < be, and b = 2bits. This represents the number x = f b−e, with x in [0, 1).
bits | the number of bits in each digit. |
bits must divide GMP_LIMB_BITS. The default value bits = 32 yields portable results on all MPFR platforms.
Definition at line 52 of file MPFRRandom.hpp.
|
inline |
Initialize the MPFRRandom object.
Definition at line 109 of file MPFRRandom.hpp.
References STATIC_ASSERT.
|
inline |
Initialize the MPFRRandom object from another one.
[in] | t | the MPFRRandom to copy. |
Definition at line 119 of file MPFRRandom.hpp.
|
inline |
Destroy the MPFRRandom object.
Definition at line 124 of file MPFRRandom.hpp.
|
inline |
Assignment operator. (But swapping is typically faster.)
[in] | t | the MPFRRandom to copy. |
Definition at line 130 of file MPFRRandom.hpp.
|
inline |
Swap with another MPFRRandom. This is a fast way of doing an assignment.
[in,out] | t | the MPFRRandom to swap with. |
Definition at line 143 of file MPFRRandom.hpp.
References std::swap().
|
inline |
Reinitialize the MPFRRandom object, setting its value to [0,1].
Definition at line 154 of file MPFRRandom.hpp.
|
inline |
Definition at line 158 of file MPFRRandom.hpp.
|
inline |
Change the sign of the MPFRRandom.
Definition at line 162 of file MPFRRandom.hpp.
|
inline |
Definition at line 166 of file MPFRRandom.hpp.
Referenced by RandomLib::MPFRRandom< bits >::AddInteger().
|
inline |
Definition at line 170 of file MPFRRandom.hpp.
|
inline |
Definition at line 174 of file MPFRRandom.hpp.
|
inline |
Definition at line 178 of file MPFRRandom.hpp.
|
inline |
Add integer k to the MPRFRandom.
[in] | k | the integer to add. |
Definition at line 184 of file MPFRRandom.hpp.
References RandomLib::MPFRRandom< bits >::Floor().
|
inline |
Compare with another MPFRRandom, *this < t.
[in,out] | r | a random generator. |
[in,out] | t | a MPFRRandom to compare. |
Definition at line 203 of file MPFRRandom.hpp.
|
inline |
Set high bit of fraction to 1.
[in,out] | r | a random generator. |
Definition at line 218 of file MPFRRandom.hpp.
References RandomLib::MPFRRandom< bits >::ExpandTo().
|
inline |
Test high bit of fraction.
[in,out] | r | a random generator. |
Definition at line 227 of file MPFRRandom.hpp.
References RandomLib::MPFRRandom< bits >::ExpandTo().
|
inline |
Return the position of the most significant bit in the MPFRRandom.
[in,out] | r | a random generator. |
The bit position is numbered such the 1/2 bit is 0, the 1/4 bit is -1, etc.
Definition at line 239 of file MPFRRandom.hpp.
Referenced by RandomLib::MPFRRandom< bits >::operator()().
|
inline |
Ensure that the k'th digit of the fraction is computed.
[in,out] | r | a random generator. |
[in] | k | the digit number (0 is the most significant, 1 is the next most significant, etc. |
Definition at line 255 of file MPFRRandom.hpp.
Referenced by RandomLib::MPFRRandom< bits >::operator()(), RandomLib::MPFRRandom< bits >::SetHighBit(), and RandomLib::MPFRRandom< bits >::TestHighBit().
|
inline |
Convert to a MPFR number without adding more bits.
[out] | val | the value of s * (n + *this). |
[in] | round | the rounding direction. |
If round is MPFR_RNDN, then the rounded midpoint of the interval represented by the MPFRRandom is returned. Otherwise it is the rounded lower or upper bound of the interval (whichever is appropriate).
Definition at line 269 of file MPFRRandom.hpp.
|
inline |
Convert to a MPFR number.
[out] | val | the value of s * (n + *this). |
[in,out] | r | a GMP random generator. |
[in] | round | the rounding direction. |
If r is NULL, then no additional random bits are generated and the lower bound, midpoint, or upper bound of the MPFRRandom interval is returned, depending on the value of round.
Definition at line 284 of file MPFRRandom.hpp.
References RandomLib::MPFRRandom< bits >::ExpandTo(), and RandomLib::MPFRRandom< bits >::LeadingBit().
|
inline |
A coin toss. (This should really be a static function. But it uses the MPFRRandom temporary variable.)
[in,out] | r | a GMP random generator. |
Definition at line 374 of file MPFRRandom.hpp.