RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Public Member Functions | List of all members
RandomLib::MPFRRandom< bits > Class Template Reference

Handling random numbers in MPFR. More...

#include <RandomLib/MPFRRandom.hpp>

Public Member Functions

 MPFRRandom ()
 
 MPFRRandom (const MPFRRandom &t)
 
 ~MPFRRandom ()
 
MPFRRandomoperator= (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
 

Detailed Description

template<int bits = 32>
class RandomLib::MPFRRandom< bits >

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 be, with x in [0, 1).

Template Parameters
bitsthe 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.

Constructor & Destructor Documentation

template<int bits = 32>
RandomLib::MPFRRandom< bits >::MPFRRandom ( )
inline

Initialize the MPFRRandom object.

Definition at line 109 of file MPFRRandom.hpp.

References STATIC_ASSERT.

template<int bits = 32>
RandomLib::MPFRRandom< bits >::MPFRRandom ( const MPFRRandom< bits > &  t)
inline

Initialize the MPFRRandom object from another one.

Parameters
[in]tthe MPFRRandom to copy.

Definition at line 119 of file MPFRRandom.hpp.

template<int bits = 32>
RandomLib::MPFRRandom< bits >::~MPFRRandom ( )
inline

Destroy the MPFRRandom object.

Definition at line 124 of file MPFRRandom.hpp.

Member Function Documentation

template<int bits = 32>
MPFRRandom& RandomLib::MPFRRandom< bits >::operator= ( const MPFRRandom< bits > &  t)
inline

Assignment operator. (But swapping is typically faster.)

Parameters
[in]tthe MPFRRandom to copy.

Definition at line 130 of file MPFRRandom.hpp.

template<int bits = 32>
void RandomLib::MPFRRandom< bits >::swap ( MPFRRandom< bits > &  t)
throw (
)
inline

Swap with another MPFRRandom. This is a fast way of doing an assignment.

Parameters
[in,out]tthe MPFRRandom to swap with.

Definition at line 143 of file MPFRRandom.hpp.

References std::swap().

template<int bits = 32>
void RandomLib::MPFRRandom< bits >::Init ( )
inline

Reinitialize the MPFRRandom object, setting its value to [0,1].

Definition at line 154 of file MPFRRandom.hpp.

template<int bits = 32>
int RandomLib::MPFRRandom< bits >::Sign ( ) const
throw (
)
inline
Returns
the sign of the MPFRRandom (± 1).

Definition at line 158 of file MPFRRandom.hpp.

template<int bits = 32>
void RandomLib::MPFRRandom< bits >::Negate ( )
throw (
)
inline

Change the sign of the MPFRRandom.

Definition at line 162 of file MPFRRandom.hpp.

template<int bits = 32>
long RandomLib::MPFRRandom< bits >::Floor ( ) const
throw (
)
inline
Returns
the floor of the MPFRRandom

Definition at line 166 of file MPFRRandom.hpp.

Referenced by RandomLib::MPFRRandom< bits >::AddInteger().

template<int bits = 32>
long RandomLib::MPFRRandom< bits >::Ceiling ( ) const
throw (
)
inline
Returns
the ceiling of the MPFRRandom

Definition at line 170 of file MPFRRandom.hpp.

template<int bits = 32>
unsigned long RandomLib::MPFRRandom< bits >::UInteger ( ) const
throw (
)
inline
Returns
the unsigned integer component of the MPFRRandom.

Definition at line 174 of file MPFRRandom.hpp.

template<int bits = 32>
unsigned long RandomLib::MPFRRandom< bits >::Size ( ) const
throw (
)
inline
Returns
the number of digits in fraction

Definition at line 178 of file MPFRRandom.hpp.

template<int bits = 32>
void RandomLib::MPFRRandom< bits >::AddInteger ( long  k)
inline

Add integer k to the MPRFRandom.

Parameters
[in]kthe integer to add.

Definition at line 184 of file MPFRRandom.hpp.

References RandomLib::MPFRRandom< bits >::Floor().

template<int bits = 32>
int RandomLib::MPFRRandom< bits >::LessThan ( gmp_randstate_t  r,
MPFRRandom< bits > &  t 
)
inline

Compare with another MPFRRandom, *this < t.

Parameters
[in,out]ra random generator.
[in,out]ta MPFRRandom to compare.
Returns
true if *this < t.

Definition at line 203 of file MPFRRandom.hpp.

template<int bits = 32>
void RandomLib::MPFRRandom< bits >::SetHighBit ( gmp_randstate_t  r)
inline

Set high bit of fraction to 1.

Parameters
[in,out]ra random generator.

Definition at line 218 of file MPFRRandom.hpp.

References RandomLib::MPFRRandom< bits >::ExpandTo().

template<int bits = 32>
int RandomLib::MPFRRandom< bits >::TestHighBit ( gmp_randstate_t  r)
inline

Test high bit of fraction.

Parameters
[in,out]ra random generator.

Definition at line 227 of file MPFRRandom.hpp.

References RandomLib::MPFRRandom< bits >::ExpandTo().

template<int bits = 32>
mp_size_t RandomLib::MPFRRandom< bits >::LeadingBit ( gmp_randstate_t  r)
inline

Return the position of the most significant bit in the MPFRRandom.

Parameters
[in,out]ra 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()().

template<int bits = 32>
void RandomLib::MPFRRandom< bits >::ExpandTo ( gmp_randstate_t  r,
mp_size_t  k 
)
inline

Ensure that the k'th digit of the fraction is computed.

Parameters
[in,out]ra random generator.
[in]kthe 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().

template<int bits = 32>
int RandomLib::MPFRRandom< bits >::operator() ( mpfr_t  val,
mpfr_rnd_t  round 
)
inline

Convert to a MPFR number without adding more bits.

Parameters
[out]valthe value of s * (n + *this).
[in]roundthe rounding direction.
Returns
the MPFR ternary result (± if val is larger/smaller than the exact sample).

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.

template<int bits = 32>
int RandomLib::MPFRRandom< bits >::operator() ( mpfr_t  val,
gmp_randstate_t  r,
mpfr_rnd_t  round 
)
inline

Convert to a MPFR number.

Parameters
[out]valthe value of s * (n + *this).
[in,out]ra GMP random generator.
[in]roundthe rounding direction.
Returns
the MPFR ternary result (± if val is larger/smaller than the exact sample).

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().

template<int bits = 32>
int RandomLib::MPFRRandom< bits >::Boolean ( gmp_randstate_t  r) const
inline

A coin toss. (This should really be a static function. But it uses the MPFRRandom temporary variable.)

Parameters
[in,out]ra GMP random generator.
Returns
true or false.

Definition at line 374 of file MPFRRandom.hpp.


The documentation for this class was generated from the following file: