Library for big numbers from http://www.ttmath.org/

Dependents:   PIDHeater82 Conceptcontroller_v_1_0 AlarmClockApp COG4050_adxl355_tilt ... more

Embed: (wiki syntax)

« Back to documentation index

ttmath::auxiliaryfunctions Namespace Reference

ttmath::auxiliaryfunctions Namespace Reference

Functions

template<class ValueType >
uint PrepareSin (ValueType &x, bool &change_sign)
template<class ValueType >
ValueType Sin0pi05 (const ValueType &x)
template<class ValueType >
ValueType ASin_0 (const ValueType &x)
template<class ValueType >
ValueType ASin_1 (const ValueType &x)
template<class ValueType >
ValueType ATan0 (const ValueType &x)
template<class ValueType >
ValueType ATan01 (const ValueType &x)
template<class ValueType >
ValueType ATanGreaterThanPlusOne (const ValueType &x)
template<class ValueType >
void SetFactorialSequence (std::vector< ValueType > &fact, uint more=20)
template<class ValueType >
ValueType SetBernoulliNumbersSum (CGamma< ValueType > &cgamma, const ValueType &n_, uint m, const volatile StopCalculating *stop=0)
template<class ValueType >
bool SetBernoulliNumbersMore (CGamma< ValueType > &cgamma, uint start, const volatile StopCalculating *stop=0)
template<class ValueType >
bool SetBernoulliNumbers (CGamma< ValueType > &cgamma, uint more=20, const volatile StopCalculating *stop=0)
template<class ValueType >
ValueType GammaFactorialHighSum (const ValueType &n, CGamma< ValueType > &cgamma, ErrorCode &err, const volatile StopCalculating *stop)
template<class ValueType >
ValueType GammaFactorialHigh (const ValueType &n, CGamma< ValueType > &cgamma, ErrorCode &err, const volatile StopCalculating *stop)
template<class ValueType >
ValueType GammaPlusHigh (ValueType n, CGamma< ValueType > &cgamma, ErrorCode &err, const volatile StopCalculating *stop)
template<class ValueType >
ValueType GammaPlusLowIntegerInt (uint n, CGamma< ValueType > &cgamma)
template<class ValueType >
ValueType GammaPlusLowInteger (const ValueType &n, CGamma< ValueType > &cgamma)
template<class ValueType >
ValueType GammaPlusLow (ValueType n, CGamma< ValueType > &cgamma, ErrorCode &err, const volatile StopCalculating *stop)
template<class ValueType >
ValueType GammaPlus (const ValueType &n, CGamma< ValueType > &cgamma, ErrorCode &err, const volatile StopCalculating *stop)
template<class ValueType >
ValueType GammaMinus (const ValueType &n, CGamma< ValueType > &cgamma, ErrorCode &err, const volatile StopCalculating *stop)
template<class ValueType >
ValueType Factorial2 (ValueType x, CGamma< ValueType > *cgamma=0, ErrorCode *err=0, const volatile StopCalculating *stop=0)

Detailed Description

trigonometric functions


Function Documentation

ValueType ttmath::auxiliaryfunctions::ASin_0 ( const ValueType &  x )

an auxiliary function for calculating the Arc Sine

we're calculating asin from the following formula: asin(x) = x + (1*x^3)/(2*3) + (1*3*x^5)/(2*4*5) + (1*3*5*x^7)/(2*4*6*7) + ... where abs(x) <= 1

we're using this formula when x is from <0, 1/2>

Definition at line 708 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::ASin_1 ( const ValueType &  x )

an auxiliary function for calculating the Arc Sine

we're calculating asin from the following formula: asin(x) = pi/2 - sqrt(2)*sqrt(1-x) * asin_temp asin_temp = 1 + (1*(1-x))/((2*3)*(2)) + (1*3*(1-x)^2)/((2*4*5)*(4)) + (1*3*5*(1-x)^3)/((2*4*6*7)*(8)) + ...

where abs(x) <= 1

we're using this formula when x is from (1/2, 1>

Definition at line 772 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::ATan0 ( const ValueType &  x )

an auxiliary function for calculating the Arc Tangent

arc tan (x) where x is in <0; 0.5) (x can be in (-0.5 ; 0.5) too)

we're using the Taylor series expanded in zero: atan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + ...

Definition at line 928 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::ATan01 ( const ValueType &  x )

an auxiliary function for calculating the Arc Tangent

where x is in <0 ; 1>

Definition at line 979 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::ATanGreaterThanPlusOne ( const ValueType &  x )

an auxiliary function for calculating the Arc Tangent where x > 1

we're using the formula: atan(x) = pi/2 - atan(1/x) for x>0

Definition at line 1050 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::Factorial2 ( ValueType  x,
CGamma< ValueType > *  cgamma = 0,
ErrorCode *  err = 0,
const volatile StopCalculating *  stop = 0 
)

an auxiliary function for calculating the factorial function

we use the formula: x! = gamma(x+1)

Definition at line 2734 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::GammaFactorialHigh ( const ValueType &  n,
CGamma< ValueType > &  cgamma,
ErrorCode &  err,
const volatile StopCalculating *  stop 
)

an auxiliary function used to calculate the Gamma() function

we calculate a helper function GammaFactorialHigh() by using Stirling's series: n! = (n/e)^n * sqrt(2*pi*n) * exp( sum(n) ) where n is a real number (not only an integer) and is sufficient large (greater than TTMATH_GAMMA_BOUNDARY) and sum(n) is calculated by GammaFactorialHighSum()

Definition at line 2448 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::GammaFactorialHighSum ( const ValueType &  n,
CGamma< ValueType > &  cgamma,
ErrorCode &  err,
const volatile StopCalculating *  stop 
)

an auxiliary function used to calculate the Gamma() function

we calculate a sum: sum(n) = sum_{m=2} { B(m) / ( (m^2 - m) * n^(m-1) ) } = 1/(12*n) - 1/(360*n^3) + 1/(1260*n^5) + ... B(m) means a mth Bernoulli number the sum starts from m=2, we calculate as long as the value will not change after adding a next part

Definition at line 2385 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::GammaMinus ( const ValueType &  n,
CGamma< ValueType > &  cgamma,
ErrorCode &  err,
const volatile StopCalculating *  stop 
)

an auxiliary function used to calculate the Gamma() function

this function is used when n is negative we use the reflection formula: gamma(1-z) * gamma(z) = pi / sin(pi*z) then: gamma(z) = pi / (sin(pi*z) * gamma(1-z))

Definition at line 2605 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::GammaPlus ( const ValueType &  n,
CGamma< ValueType > &  cgamma,
ErrorCode &  err,
const volatile StopCalculating *  stop 
)

an auxiliary function used to calculate the Gamma() function

Definition at line 2586 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::GammaPlusHigh ( ValueType  n,
CGamma< ValueType > &  cgamma,
ErrorCode &  err,
const volatile StopCalculating *  stop 
)

an auxiliary function used to calculate the Gamma() function

Gamma(x) = GammaFactorialHigh(x-1)

Definition at line 2481 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::GammaPlusLow ( ValueType  n,
CGamma< ValueType > &  cgamma,
ErrorCode &  err,
const volatile StopCalculating *  stop 
)

an auxiliary function used to calculate the Gamma() function

we use this function when n is a small value (from 0 to TTMATH_GAMMA_BOUNDARY] we use a recurrence formula: gamma(z+1) = z * gamma(z) then: gamma(z) = gamma(z+1) / z

e.g. gamma(3.89) = gamma(2001.89) / ( 3.89 * 4.89 * 5.89 * ... * 1999.89 * 2000.89 )

Definition at line 2555 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::GammaPlusLowInteger ( const ValueType &  n,
CGamma< ValueType > &  cgamma 
)

an auxiliary function used to calculate the Gamma() function

we use this function when n is integer and a small value (from 0 to TTMATH_GAMMA_BOUNDARY]

Definition at line 2533 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::GammaPlusLowIntegerInt ( uint  n,
CGamma< ValueType > &  cgamma 
)

an auxiliary function used to calculate the Gamma() function

we use this function when n is integer and a small value (from 0 to TTMATH_GAMMA_BOUNDARY] we use the formula: gamma(n) = (n-1)! = 1 * 2 * 3 * ... * (n-1)

Definition at line 2500 of file ttmath.h.

uint ttmath::auxiliaryfunctions::PrepareSin ( ValueType &  x,
bool &  change_sign 
)

an auxiliary function for calculating the Sine (you don't have to call this function)

Definition at line 358 of file ttmath.h.

bool ttmath::auxiliaryfunctions::SetBernoulliNumbers ( CGamma< ValueType > &  cgamma,
uint  more = 20,
const volatile StopCalculating *  stop = 0 
)

this function is used to calculate Bernoulli numbers, returns false if there was a stop signal, 'more' means how many values should be added at the end

e.g. typedef Big<1,2> MyBig; CGamma<MyBig> cgamma; SetBernoulliNumbers(cgamma, 3); now we have three first Bernoulli numbers: 1 -0.5 0.16667

SetBernoulliNumbers(cgamma, 4); now we have 7 Bernoulli numbers: 1 -0.5 0.16667 0 -0.0333 0 0.0238

Definition at line 2343 of file ttmath.h.

bool ttmath::auxiliaryfunctions::SetBernoulliNumbersMore ( CGamma< ValueType > &  cgamma,
uint  start,
const volatile StopCalculating *  stop = 0 
)

an auxiliary function used to calculate Bernoulli numbers start is >= 2

we use the recurrence formula: B(m) = 1 / (2*(1 - 2^m)) * sum(m) where sum(m) is calculated by SetBernoulliNumbersSum()

Definition at line 2283 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::SetBernoulliNumbersSum ( CGamma< ValueType > &  cgamma,
const ValueType &  n_,
uint  m,
const volatile StopCalculating *  stop = 0 
)

an auxiliary function used to calculate Bernoulli numbers

this function returns a sum: sum(m) = sum_{k=0}^{m-1} {2^k * (m k) * B(k)} k in [0, m-1] (m k) means binomial coefficient = (m! / (k! * (m-k)!))

you should have sufficient factorials in cgamma.fact (cgamma.fact should have at least m items)

n_ should be equal 2

Definition at line 2232 of file ttmath.h.

void ttmath::auxiliaryfunctions::SetFactorialSequence ( std::vector< ValueType > &  fact,
uint  more = 20 
)

this function is used to store factorials in a given container 'more' means how many values should be added at the end

e.g. std::vector<ValueType> fact; SetFactorialSequence(fact, 3); now the container has three values: 1 1 2

SetFactorialSequence(fact, 2); now the container has five values: 1 1 2 6 24

Definition at line 2198 of file ttmath.h.

ValueType ttmath::auxiliaryfunctions::Sin0pi05 ( const ValueType &  x )

an auxiliary function for calculating the Sine (you don't have to call this function)

it returns Sin(x) where 'x' is from <0, PI/2> we're calculating the Sin with using Taylor series in zero or PI/2 (depending on which point of these two points is nearer to the 'x')

Taylor series: sin(x) = sin(a) + cos(a)*(x-a)/(1!)

  • sin(a)*((x-a)^2)/(2!) - cos(a)*((x-a)^3)/(3!) + sin(a)*((x-a)^4)/(4!) + ...

when a=0 it'll be: sin(x) = (x)/(1!) - (x^3)/(3!) + (x^5)/(5!) - (x^7)/(7!) + (x^9)/(9!) ...

and when a=PI/2: sin(x) = 1 - ((x-PI/2)^2)/(2!) + ((x-PI/2)^4)/(4!) - ((x-PI/2)^6)/(6!) ...

Definition at line 423 of file ttmath.h.