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 Namespace Reference

ttmath Namespace Reference

a namespace for the TTMath library More...

Namespaces

namespace  auxiliaryfunctions

Data Structures

class  Big
 Big implements the floating point numbers. More...
class  Int
 Int implements a big integer value with a sign. More...
class  Misc
class  Objects
class  History
struct  CGamma
class  Parser
 Mathematical parser. More...
class  ThreadLock
struct  Conv
class  StopCalculating
class  ExceptionInfo
class  ReferenceError
class  RuntimeError
class  UInt
 UInt implements a big integer value without a sign. More...
class  UInt< 0 >

Typedefs

typedef unsigned int uint
typedef unsigned long long int ulint

Enumerations

enum  LibTypeCode
enum  ErrorCode

Functions

template<class ValueType >
ValueType SkipFraction (const ValueType &x)
template<class ValueType >
ValueType Round (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Ceil (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Floor (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Ln (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Log (const ValueType &x, const ValueType &base, ErrorCode *err=0)
template<class ValueType >
ValueType Exp (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Sin (ValueType x, ErrorCode *err=0)
template<class ValueType >
ValueType Cos (ValueType x, ErrorCode *err=0)
template<class ValueType >
ValueType Tan (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Tg (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Cot (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Ctg (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType ASin (ValueType x, ErrorCode *err=0)
template<class ValueType >
ValueType ACos (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType ATan (ValueType x)
template<class ValueType >
ValueType ATg (const ValueType &x)
template<class ValueType >
ValueType ACot (const ValueType &x)
template<class ValueType >
ValueType ACtg (const ValueType &x)
template<class ValueType >
ValueType Sinh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Cosh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Tanh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Tgh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Coth (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Ctgh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType ASinh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType ACosh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType ATanh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType ATgh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType ACoth (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType ACtgh (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType DegToRad (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType RadToDeg (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType DegToDeg (const ValueType &d, const ValueType &m, const ValueType &s, ErrorCode *err=0)
template<class ValueType >
ValueType DegToRad (const ValueType &d, const ValueType &m, const ValueType &s, ErrorCode *err=0)
template<class ValueType >
ValueType GradToRad (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType RadToGrad (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType DegToGrad (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType DegToGrad (const ValueType &d, const ValueType &m, const ValueType &s, ErrorCode *err=0)
template<class ValueType >
ValueType GradToDeg (const ValueType &x, ErrorCode *err=0)
template<class ValueType >
ValueType Sqrt (ValueType x, ErrorCode *err=0)
template<class ValueType >
ValueType Root (ValueType x, const ValueType &index, ErrorCode *err=0)
template<class ValueType >
ValueType Abs (const ValueType &x)
template<class ValueType >
ValueType Sgn (ValueType x)
template<class ValueType >
ValueType Mod (ValueType a, const ValueType &b, ErrorCode *err=0)
template<class ValueType >
ValueType Gamma (const ValueType &n, CGamma< ValueType > &cgamma, ErrorCode *err=0, const volatile StopCalculating *stop=0)
template<class ValueType >
ValueType Gamma (const ValueType &n, ErrorCode *err=0)
template<class ValueType >
ValueType Factorial (const ValueType &x, CGamma< ValueType > &cgamma, ErrorCode *err=0, const volatile StopCalculating *stop=0)
template<class ValueType >
ValueType Factorial (const ValueType &x, ErrorCode *err=0)

Variables

pthread_mutex_t ttmath_mutex

Detailed Description

a namespace for the TTMath library


Typedef Documentation

typedef unsigned long uint

on 32bit platforms one word (uint, sint) will be equal 32bits

on 64bit platforms one word (uint, sint) will be equal 64bits

Definition at line 155 of file ttmathtypes.h.

typedef uint64_t ulint

on 32 bit platform ulint and slint will be equal 64 bits

Definition at line 164 of file ttmathtypes.h.


Enumeration Type Documentation

enum ErrorCode

error codes

Definition at line 341 of file ttmathtypes.h.

lib type codes: asm_vc_32 - with asm code designed for Microsoft Visual C++ (32 bits) asm_gcc_32 - with asm code designed for GCC (32 bits) asm_vc_64 - with asm for VC (64 bit) asm_gcc_64 - with asm for GCC (64 bit) no_asm_32 - pure C++ version (32 bit) - without any asm code no_asm_64 - pure C++ version (64 bit) - without any asm code

Definition at line 327 of file ttmathtypes.h.


Function Documentation

ValueType ttmath::Abs ( const ValueType &  x )

absolute value of x e.g. -2 = 2 2 = 2

Definition at line 2126 of file ttmath.h.

ValueType ttmath::ACos ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the Arc Cosine

we're using the formula: acos(x) = pi/2 - asin(x)

Definition at line 903 of file ttmath.h.

ValueType ttmath::ACosh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic cosine

acosh(x) = ln( x + sqrt(x^2 - 1) ) x in <1, infinity)

Definition at line 1380 of file ttmath.h.

ValueType ttmath::ACot ( const ValueType &  x )

this function calculates the Arc Cotangent

we're using the formula: actan(x) = pi/2 - atan(x)

Definition at line 1129 of file ttmath.h.

ValueType ttmath::ACoth ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic cotangent

acoth(x) = 0.5 * ln( (x+1) / (x-1) ) x in (-infinity, -1) or (1, infinity)

Definition at line 1482 of file ttmath.h.

ValueType ttmath::ACtg ( const ValueType &  x )

this function calculates the Arc Cotangent look at the description of ACot(...)

(the abbreviation of Arc Cotangent can be 'actg' as well)

Definition at line 1147 of file ttmath.h.

ValueType ttmath::ACtgh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic cotantent

Definition at line 1522 of file ttmath.h.

ValueType ttmath::ASin ( ValueType  x,
ErrorCode *  err = 0 
)

this function calculates the Arc Sine x is from <-1,1>

Definition at line 848 of file ttmath.h.

ValueType ttmath::ASinh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic sine

asinh(x) = ln( x + sqrt(x^2 + 1) )

Definition at line 1344 of file ttmath.h.

ValueType ttmath::ATan ( ValueType  x )

this function calculates the Arc Tangent

Definition at line 1078 of file ttmath.h.

ValueType ttmath::ATanh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic tangent

atanh(x) = 0.5 * ln( (1+x) / (1-x) ) x in (-1, 1)

Definition at line 1429 of file ttmath.h.

ValueType ttmath::ATg ( const ValueType &  x )

this function calculates the Arc Tangent look at the description of ATan(...)

(the abbreviation of Arc Tangent can be 'atg' as well)

Definition at line 1116 of file ttmath.h.

ValueType ttmath::ATgh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic tantent

Definition at line 1470 of file ttmath.h.

ValueType ttmath::Ceil ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function returns a value representing the smallest integer that is greater than or equal to x

Ceil(-3.7) = -3 Ceil(-3.1) = -3 Ceil(-3.0) = -3 Ceil(4.0) = 4 Ceil(4.2) = 5 Ceil(4.8) = 5

Definition at line 138 of file ttmath.h.

ValueType ttmath::Cos ( ValueType  x,
ErrorCode *  err = 0 
)

this function calulates the Cosine we're using the formula cos(x) = sin(x + PI/2)

Definition at line 574 of file ttmath.h.

ValueType ttmath::Cosh ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the Hyperbolic Cosine

we're using the formula cosh(x)= ( e^x + e^(-x) ) / 2

Definition at line 1199 of file ttmath.h.

ValueType ttmath::Cot ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calulates the Cotangent we're using the formula tan(x) = cos(x) / sin(x)

(why do we make it in this way? look at information in Tan() function)

Definition at line 654 of file ttmath.h.

ValueType ttmath::Coth ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the Hyperbolic Cotangent

we're using the formula coth(x)= ( e^x + e^(-x) ) / ( e^x - e^(-x) )

Definition at line 1279 of file ttmath.h.

ValueType ttmath::Ctg ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calulates the Cotangent look at the description of Cot(...)

(the abbreviation of Cotangent can be 'ctg' as well)

Definition at line 682 of file ttmath.h.

ValueType ttmath::Ctgh ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the Hyperbolic Cotangent look at the description of Coth(...)

(the abbreviation of Hyperbolic Cotangent can be 'ctgh' as well)

Definition at line 1324 of file ttmath.h.

ValueType ttmath::DegToDeg ( const ValueType &  d,
const ValueType &  m,
const ValueType &  s,
ErrorCode *  err = 0 
)

this function converts degrees in the long format into one value

long format: (degrees, minutes, seconds) minutes and seconds must be greater than or equal zero

result: if d>=0 : result= d + ((s/60)+m)/60 if d<0 : result= d - ((s/60)+m)/60

((s/60)+m)/60 = (s+60*m)/3600 (second version is faster because there's only one division)

for example: DegToDeg(10, 30, 0) = 10.5 DegToDeg(10, 24, 35.6)=10.4098(8)

Definition at line 1625 of file ttmath.h.

ValueType ttmath::DegToGrad ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts degrees to gradians

it returns: x * 200 / 180

Definition at line 1750 of file ttmath.h.

ValueType ttmath::DegToGrad ( const ValueType &  d,
const ValueType &  m,
const ValueType &  s,
ErrorCode *  err = 0 
)

this function converts degrees in the long format to gradians

Definition at line 1782 of file ttmath.h.

ValueType ttmath::DegToRad ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts degrees to radians

it returns: x * pi / 180

Definition at line 1545 of file ttmath.h.

ValueType ttmath::DegToRad ( const ValueType &  d,
const ValueType &  m,
const ValueType &  s,
ErrorCode *  err = 0 
)

this function converts degrees in the long format to radians

Definition at line 1664 of file ttmath.h.

ValueType ttmath::Exp ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the expression e^x

Definition at line 319 of file ttmath.h.

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

the factorial from given 'x' e.g. Factorial(4) = 4! = 1*2*3*4

it's multithread safe, you should create a CGamma<> object and use it whenever you call the Factorial() e.g. typedef Big<1,2> MyBig; MyBig x=234, y=54345; CGamma<MyBig> cgamma; std::cout << Factorial(x, cgamma) << std::endl; std::cout << Factorial(y, cgamma) << std::endl; in the CGamma<> object the function stores some coefficients (factorials, Bernoulli numbers), and they will be reused in next calls to the function

each thread should have its own CGamma<> object, and you can use these objects with Gamma() function too

Definition at line 2782 of file ttmath.h.

ValueType ttmath::Factorial ( const ValueType &  x,
ErrorCode *  err = 0 
)

the factorial from given 'x' e.g. Factorial(4) = 4! = 1*2*3*4

note: this function should be used only in a single-thread environment

Definition at line 2797 of file ttmath.h.

ValueType ttmath::Floor ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function returns a value representing the largest integer that is less than or equal to x

Floor(-3.6) = -4 Floor(-3.1) = -4 Floor(-3) = -3 Floor(2) = 2 Floor(2.3) = 2 Floor(2.8) = 2

Definition at line 185 of file ttmath.h.

ValueType ttmath::Gamma ( const ValueType &  n,
CGamma< ValueType > &  cgamma,
ErrorCode *  err = 0,
const volatile StopCalculating *  stop = 0 
)

this function calculates the Gamma function

it's multithread safe, you should create a CGamma<> object and use it whenever you call the Gamma() e.g. typedef Big<1,2> MyBig; MyBig x=234, y=345.53; CGamma<MyBig> cgamma; std::cout << Gamma(x, cgamma) << std::endl; std::cout << Gamma(y, cgamma) << std::endl; in the CGamma<> object the function stores some coefficients (factorials, Bernoulli numbers), and they will be reused in next calls to the function

each thread should have its own CGamma<> object, and you can use these objects with Factorial() function too

Definition at line 2654 of file ttmath.h.

ValueType ttmath::Gamma ( const ValueType &  n,
ErrorCode *  err = 0 
)

this function calculates the Gamma function

note: this function should be used only in a single-thread environment

Definition at line 2714 of file ttmath.h.

ValueType ttmath::GradToDeg ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts degrees to gradians

it returns: x * 180 / 200

Definition at line 1800 of file ttmath.h.

ValueType ttmath::GradToRad ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts gradians to radians

it returns: x * pi / 200

Definition at line 1682 of file ttmath.h.

ValueType ttmath::Ln ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the natural logarithm (logarithm with the base 'e')

Definition at line 233 of file ttmath.h.

ValueType ttmath::Log ( const ValueType &  x,
const ValueType &  base,
ErrorCode *  err = 0 
)

this function calculates the logarithm

Definition at line 274 of file ttmath.h.

ValueType ttmath::Mod ( ValueType  a,
const ValueType &  b,
ErrorCode *  err = 0 
)

the remainder from a division

e.g. mod( 12.6 ; 3) = 0.6 because 12.6 = 3*4 + 0.6 mod(-12.6 ; 3) = -0.6 bacause -12.6 = 3*(-4) + (-0.6) mod( 12.6 ; -3) = 0.6 mod(-12.6 ; -3) = -0.6

Definition at line 2160 of file ttmath.h.

ValueType ttmath::RadToDeg ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts radians to degrees

it returns: x * 180 / pi

Definition at line 1581 of file ttmath.h.

ValueType ttmath::RadToGrad ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts radians to gradians

it returns: x * 200 / pi

Definition at line 1718 of file ttmath.h.

ValueType ttmath::Root ( ValueType  x,
const ValueType &  index,
ErrorCode *  err = 0 
)

indexth Root of x index must be integer and not negative <0;1;2;3....)

if index==0 the result is one if x==0 the result is zero and we assume root(0;0) is not defined

if index is even (2;4;6...) the result is x^(1/index) and x>0 if index is odd (1;2;3;...) the result is either -(abs(x)^(1/index)) if x<0 or x^(1/index)) if x>0

(for index==1 the result is equal x)

Definition at line 2067 of file ttmath.h.

ValueType ttmath::Round ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function rounds to the nearest integer value e.g 2.2 = 2 2.7 = 3 -2.2 = -2 -2.7 = -3

Definition at line 105 of file ttmath.h.

ValueType ttmath::Sgn ( ValueType  x )

it returns the sign of the value e.g. -2 = -1 0 = 0 10 = 1

Definition at line 2142 of file ttmath.h.

ValueType ttmath::Sin ( ValueType  x,
ErrorCode *  err = 0 
)

this function calculates the Sine

Definition at line 518 of file ttmath.h.

ValueType ttmath::Sinh ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the Hyperbolic Sine

we're using the formula sinh(x)= ( e^x - e^(-x) ) / 2

Definition at line 1167 of file ttmath.h.

ValueType ttmath::SkipFraction ( const ValueType &  x )

this function skips the fraction from x e.g 2.2 = 2 2.7 = 2 -2.2 = 2 -2.7 = 2

Definition at line 88 of file ttmath.h.

ValueType ttmath::Sqrt ( ValueType  x,
ErrorCode *  err = 0 
)

this function calculates the square root

Sqrt(9) = 3

Definition at line 1844 of file ttmath.h.

ValueType ttmath::Tan ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calulates the Tangent we're using the formula tan(x) = sin(x) / cos(x)

it takes more time than calculating the Tan directly from for example Taylor series but should be a bit preciser because Tan receives its values from -infinity to +infinity and when we calculate it from any series then we can make a greater mistake than calculating 'sin/cos'

Definition at line 612 of file ttmath.h.

ValueType ttmath::Tanh ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the Hyperbolic Tangent

we're using the formula tanh(x)= ( e^x - e^(-x) ) / ( e^x + e^(-x) )

Definition at line 1231 of file ttmath.h.

ValueType ttmath::Tg ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calulates the Tangent look at the description of Tan(...)

(the abbreviation of Tangent can be 'tg' as well)

Definition at line 640 of file ttmath.h.

ValueType ttmath::Tgh ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the Hyperbolic Tangent look at the description of Tanh(...)

(the abbreviation of Hyperbolic Tangent can be 'tgh' as well)

Definition at line 1268 of file ttmath.h.


Variable Documentation

pthread_mutex_t ttmath_mutex

ttmath_mutex will be defined by TTMATH_MULTITHREADS_HELPER macro