TTMath  0.9.4
 C++ bignum library
Public Member Functions | Data Fields
ttmath::CGamma< ValueType > Struct Template Reference

#include <ttmathobjects.h>

Collaboration diagram for ttmath::CGamma< ValueType >:
Collaboration graph
[legend]

Public Member Functions

void InitAll ()
 

Data Fields

std::vector< ValueType > fact
 
std::vector< ValueType > bern
 
History< ValueType > history
 

Detailed Description

template<class ValueType>
struct ttmath::CGamma< ValueType >

this is an auxiliary class used when calculating Gamma() or Factorial()

in multithreaded environment you can provide an object of this class to the Gamma() or Factorial() function, e.g;

typedef Big<1, 3> MyBig;
MyBig x = 123456;
CGamma<MyBig> cgamma;
std::cout << Gamma(x, cgamma);

each thread should have its own CGamma<> object

in a single-thread environment a CGamma<> object is a static variable and you don't have to explicitly use it, e.g.

typedef Big<1, 3> MyBig;
MyBig x = 123456;
std::cout << Gamma(x);

Definition at line 742 of file ttmathobjects.h.

Member Function Documentation

§ InitAll()

template<class ValueType >
void ttmath::CGamma< ValueType >::InitAll ( )

this method prepares some coefficients: factorials and Bernoulli numbers stored in 'fact' and 'bern' objects

how many values should be depends on the size of the mantissa - if the mantissa is larger then we must calculate more values for a mantissa which consists of 256 bits (8 words on a 32bit platform) we have to calculate about 30 values (the size of fact and bern will be 30), and for a 2048 bits mantissa we have to calculate 306 coefficients

you don't have to call this method, these coefficients will be automatically calculated when they are needed

you must note that calculating these coefficients is a little time-consuming operation, (especially when the mantissa is large) and first call to Gamma() or Factorial() can take more time than next calls, and in the end this is the point when InitAll() comes in handy: you can call this method somewhere at the beginning of your program

this method prepares some coefficients: factorials and Bernoulli numbers stored in 'fact' and 'bern' objects

we're defining the method here because we're using Gamma() function which is not available in ttmathobjects.h

read the doc info in ttmathobjects.h file where CGamma<> struct is declared

Definition at line 2840 of file ttmath.h.

References ttmath::Gamma(), and TTMATH_GAMMA_BOUNDARY.

Referenced by ttmath::Parser< ValueType >::InitCGamma().

2841  {
2842  ValueType x = TTMATH_GAMMA_BOUNDARY + 1;
2843 
2844  // history.Remove(x) removes only one object
2845  // we must be sure that there are not others objects with the key 'x'
2846  while( history.Remove(x) )
2847  {
2848  }
2849 
2850  // the simplest way to initialize is to call the Gamma function with (TTMATH_GAMMA_BOUNDARY + 1)
2851  // when x is larger then fewer coefficients we need
2852  Gamma(x, *this);
2853  }
History< ValueType > history
ValueType Gamma(const ValueType &n, CGamma< ValueType > &cgamma, ErrorCode *err=0, const volatile StopCalculating *stop=0)
Definition: ttmath.h:2679
#define TTMATH_GAMMA_BOUNDARY
Definition: ttmathtypes.h:338

Field Documentation

§ bern

template<class ValueType>
std::vector<ValueType> ttmath::CGamma< ValueType >::bern

this table holds Bernoulli numbers 1 -0.5 0.166666666666666666666666667 0 -0.0333333333333333333333333333 0 0.0238095238095238095238095238 0 -0.0333333333333333333333333333 0 0.075757575757575757575757576 .....

Definition at line 773 of file ttmathobjects.h.

§ fact

template<class ValueType>
std::vector<ValueType> ttmath::CGamma< ValueType >::fact

this table holds factorials 1 1 2 6 24 120 720 .......

Definition at line 755 of file ttmathobjects.h.

§ history

template<class ValueType>
History<ValueType> ttmath::CGamma< ValueType >::history

here we store some calculated values (this is for speeding up, if the next argument of Gamma() or Factorial() is in the 'history' then the result we are not calculating but simply return from the 'history' object)

Definition at line 782 of file ttmathobjects.h.

Referenced by ttmath::Gamma().


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