aGrUM  0.14.2
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 45 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 36 of file gammaLog2.cpp.

36  :
37  __requires_precision{requires_precision} {
38  GUM_CONSTRUCTOR(GammaLog2);
39  }
GammaLog2(bool requires_precision=false)
Default constructor.
Definition: gammaLog2.cpp:36
bool __requires_precision
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:111

◆ GammaLog2() [2/3]

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

Copy constructor.

Parameters
fromThe gum::GammaLog2 to copy.

Definition at line 42 of file gammaLog2.cpp.

References __requires_precision.

42  :
43  __requires_precision{from.__requires_precision} {
44  GUM_CONS_CPY(GammaLog2);
45  }
GammaLog2(bool requires_precision=false)
Default constructor.
Definition: gammaLog2.cpp:36
bool __requires_precision
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:111

◆ GammaLog2() [3/3]

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

Move constructor.

Parameters
fromThe gum::GammaLog2 to move.

Definition at line 48 of file gammaLog2.cpp.

48  :
49  __requires_precision{from.__requires_precision} {
50  GUM_CONS_MOV(GammaLog2);
51  }
GammaLog2(bool requires_precision=false)
Default constructor.
Definition: gammaLog2.cpp:36
bool __requires_precision
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:111

◆ ~GammaLog2()

gum::GammaLog2::~GammaLog2 ( )

Class destructor.

Definition at line 54 of file gammaLog2.cpp.

References __small_values.

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

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 29 of file gammaLog2_inl.h.

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

Referenced by operator()().

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

References gammaLog2().

52  {
53  return gammaLog2(x);
54  }
double gammaLog2(double x) const
Returns log2 ( gamma (x) ) for x >= 0.
Definition: gammaLog2_inl.h:29
+ 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 56 of file gammaLog2_inl.h.

References __requires_precision.

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

Member Data Documentation

◆ __1log2

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

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

Definition at line 114 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 117 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 111 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 120 of file gammaLog2.h.

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


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