aGrUM  0.16.0
gum::GammaLog2 Class Reference

The class for computing Log2 (Gamma(x)) More...

#include <agrum/core/math/gammaLog2.h>

+ Collaboration diagram for gum::GammaLog2:

Public Member Functions

Constructors / Destructors
 GammaLog2 (bool requires_precision=false)
 Default constructor. More...
 
 GammaLog2 (const GammaLog2 &from)
 Copy constructor. More...
 
 GammaLog2 (GammaLog2 &&from)
 Move constructor. More...
 
 ~GammaLog2 ()
 Class destructor. More...
 
Operators
double operator() (double x) const
 Returns log2 ( gamma (x) ) for x > 0. More...
 
void setPrecision (bool p)
 Sets whether we need more precision for small values. More...
 
double gammaLog2 (double x) const
 Returns log2 ( gamma (x) ) for x >= 0. More...
 

Detailed Description

The class for computing Log2 (Gamma(x))

Definition at line 48 of file gammaLog2.h.

Constructor & Destructor Documentation

◆ GammaLog2() [1/3]

gum::GammaLog2::GammaLog2 ( bool  requires_precision = false)

Default constructor.

Parameters
requires_precisionSet if precision is required or not.

Definition at line 39 of file gammaLog2.cpp.

39  :
40  __requires_precision{requires_precision} {
41  GUM_CONSTRUCTOR(GammaLog2);
42  }
GammaLog2(bool requires_precision=false)
Default constructor.
Definition: gammaLog2.cpp:39
bool __requires_precision
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:114

◆ GammaLog2() [2/3]

gum::GammaLog2::GammaLog2 ( const GammaLog2 from)

Copy constructor.

Parameters
fromThe gum::GammaLog2 to copy.

Definition at line 45 of file gammaLog2.cpp.

References __requires_precision.

45  :
46  __requires_precision{from.__requires_precision} {
47  GUM_CONS_CPY(GammaLog2);
48  }
GammaLog2(bool requires_precision=false)
Default constructor.
Definition: gammaLog2.cpp:39
bool __requires_precision
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:114

◆ GammaLog2() [3/3]

gum::GammaLog2::GammaLog2 ( GammaLog2 &&  from)

Move constructor.

Parameters
fromThe gum::GammaLog2 to move.

Definition at line 51 of file gammaLog2.cpp.

51  :
52  __requires_precision{from.__requires_precision} {
53  GUM_CONS_MOV(GammaLog2);
54  }
GammaLog2(bool requires_precision=false)
Default constructor.
Definition: gammaLog2.cpp:39
bool __requires_precision
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:114

◆ ~GammaLog2()

gum::GammaLog2::~GammaLog2 ( )

Class destructor.

Definition at line 57 of file gammaLog2.cpp.

References __small_values.

57 { GUM_DESTRUCTOR(GammaLog2); }
GammaLog2(bool requires_precision=false)
Default constructor.
Definition: gammaLog2.cpp:39

Member Function Documentation

◆ gammaLog2()

ALWAYS_INLINE double gum::GammaLog2::gammaLog2 ( double  x) const

Returns log2 ( gamma (x) ) for x >= 0.

Parameters
xA positive double.
Returns
Returns log2 ( gamma (x) ) for x >= 0.
Exceptions
OutOfBoundsRaised if x <= 0.

Definition at line 32 of file gammaLog2_inl.h.

References __1log2, __log_sqrt_2pi, __requires_precision, __small_values, and GUM_ERROR.

Referenced by operator()().

32  {
33  if (x <= 0)
34  GUM_ERROR(OutOfBounds,
35  "log2(gamma()) should be called with a positive argument");
36 
37  // if x is small, use precomputed values
38  if (x < 50) {
40  Idx index = int(x * 100);
41  return __small_values[index]
42  + (__small_values[index + 1] - __small_values[index])
43  * double(x * 100 - index);
44  } else {
45  Idx index = int(x * 100 + 0.5);
46  return __small_values[index];
47  }
48  }
49 
50  // returns the approximation by the stirling formula
51  return (__log_sqrt_2pi + (x - 0.5f) * log(x) - x + log(1.0 + 1.0 / (12 * x)))
52  * __1log2;
53  }
static constexpr double __log_sqrt_2pi
The value of std::log ( std::sqrt(2pi) ).
Definition: gammaLog2.h:120
bool __requires_precision
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:114
static const std::vector< double > __small_values
The 5000 values from 0 to 50 by step of 1/100.
Definition: gammaLog2.h:123
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
static constexpr double __1log2
The value of 1 / std::log(2).
Definition: gammaLog2.h:117
+ Here is the caller graph for this function:

◆ operator()()

ALWAYS_INLINE double gum::GammaLog2::operator() ( double  x) const

Returns log2 ( gamma (x) ) for x > 0.

Exceptions
OutOfBoundsRaised if raised if x <= 0.

Definition at line 55 of file gammaLog2_inl.h.

References gammaLog2().

55  {
56  return gammaLog2(x);
57  }
double gammaLog2(double x) const
Returns log2 ( gamma (x) ) for x >= 0.
Definition: gammaLog2_inl.h:32
+ Here is the call graph for this function:

◆ setPrecision()

INLINE void gum::GammaLog2::setPrecision ( bool  p)

Sets whether we need more precision for small values.

Parameters
pIf true, precision is enable.

Definition at line 59 of file gammaLog2_inl.h.

References __requires_precision.

59 { __requires_precision = prec; }
bool __requires_precision
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:114

Member Data Documentation

◆ __1log2

constexpr double gum::GammaLog2::__1log2 {M_LOG2E}
staticprivate

The value of 1 / std::log(2).

Definition at line 117 of file gammaLog2.h.

Referenced by gammaLog2().

◆ __log_sqrt_2pi

constexpr double gum::GammaLog2::__log_sqrt_2pi {GUM_LOG_SQRT_2PI}
staticprivate

The value of std::log ( std::sqrt(2pi) ).

Definition at line 120 of file gammaLog2.h.

Referenced by gammaLog2().

◆ __requires_precision

bool gum::GammaLog2::__requires_precision {false}
private

Indicates whether we need more precision for small values.

Definition at line 114 of file gammaLog2.h.

Referenced by GammaLog2(), gammaLog2(), and setPrecision().

◆ __small_values

const std::vector< double > gum::GammaLog2::__small_values
staticprivate

The 5000 values from 0 to 50 by step of 1/100.

Definition at line 123 of file gammaLog2.h.

Referenced by gammaLog2(), and ~GammaLog2().


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