All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Namespaces | Classes | Typedefs | Enumerations | Functions
ttmath Namespace Reference

a namespace for the TTMath library More...

Namespaces

 auxiliaryfunctions
 

Classes

class  Big
 Big implements the floating point numbers. More...
 
class  Dec
 
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 signed int sint
 
typedef uint64_t ulint
 
typedef int64_t slint
 

Enumerations

enum  LibTypeCode {
  asm_vc_32 = 0, asm_gcc_32, asm_vc_64, asm_gcc_64,
  no_asm_32, no_asm_64
}
 
enum  ErrorCode {
  err_ok = 0, err_nothing_has_read, err_unknown_character, err_unexpected_final_bracket,
  err_stack_not_clear, err_unknown_variable, err_division_by_zero, err_interrupt,
  err_overflow, err_unknown_function, err_unknown_operator, err_unexpected_semicolon_operator,
  err_improper_amount_of_arguments, err_improper_argument, err_unexpected_end, err_internal_error,
  err_incorrect_name, err_incorrect_value, err_variable_exists, err_variable_loop,
  err_functions_loop, err_must_be_only_one_value, err_object_exists, err_unknown_object,
  err_still_calculating, err_in_short_form_used_function, err_percent_from
}
 

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)
 

Detailed Description

a namespace for the TTMath library

Typedef Documentation

typedef signed int ttmath::sint
typedef int64_t ttmath::slint
typedef unsigned int ttmath::uint

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

typedef uint64_t ttmath::ulint

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

Enumeration Type Documentation

error codes

Enumerator
err_ok 
err_nothing_has_read 
err_unknown_character 
err_unexpected_final_bracket 
err_stack_not_clear 
err_unknown_variable 
err_division_by_zero 
err_interrupt 
err_overflow 
err_unknown_function 
err_unknown_operator 
err_unexpected_semicolon_operator 
err_improper_amount_of_arguments 
err_improper_argument 
err_unexpected_end 
err_internal_error 
err_incorrect_name 
err_incorrect_value 
err_variable_exists 
err_variable_loop 
err_functions_loop 
err_must_be_only_one_value 
err_object_exists 
err_unknown_object 
err_still_calculating 
err_in_short_form_used_function 
err_percent_from 

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

Enumerator
asm_vc_32 
asm_gcc_32 
asm_vc_64 
asm_gcc_64 
no_asm_32 
no_asm_64 

Function Documentation

template<class ValueType >
ValueType ttmath::Abs ( const ValueType &  x)

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

template<class ValueType >
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)

template<class ValueType >
ValueType ttmath::ACosh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic cosine

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

template<class ValueType >
ValueType ttmath::ACot ( const ValueType &  x)

this function calculates the Arc Cotangent

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

template<class ValueType >
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)

template<class ValueType >
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)

template<class ValueType >
ValueType ttmath::ACtgh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic cotantent

template<class ValueType >
ValueType ttmath::ASin ( ValueType  x,
ErrorCode *  err = 0 
)

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

template<class ValueType >
ValueType ttmath::ASinh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic sine

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

template<class ValueType >
ValueType ttmath::ATan ( ValueType  x)

this function calculates the Arc Tangent

template<class ValueType >
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)

template<class ValueType >
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)

template<class ValueType >
ValueType ttmath::ATgh ( const ValueType &  x,
ErrorCode *  err = 0 
)

inverse hyperbolic tantent

template<class ValueType >
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

template<class ValueType >
ValueType ttmath::Cos ( ValueType  x,
ErrorCode *  err = 0 
)

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

template<class ValueType >
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

template<class ValueType >
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)

template<class ValueType >
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) )

template<class ValueType >
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)

template<class ValueType >
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)

template<class ValueType >
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)

template<class ValueType >
ValueType ttmath::DegToGrad ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts degrees to gradians

it returns: x * 200 / 180

template<class ValueType >
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

template<class ValueType >
ValueType ttmath::DegToRad ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts degrees to radians

it returns: x * pi / 180

template<class ValueType >
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

template<class ValueType >
ValueType ttmath::Exp ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function calculates the expression e^x

template<class ValueType >
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

template<class ValueType >
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

template<class ValueType >
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

template<class ValueType >
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

template<class ValueType >
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

template<class ValueType >
ValueType ttmath::GradToDeg ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts degrees to gradians

it returns: x * 180 / 200

template<class ValueType >
ValueType ttmath::GradToRad ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts gradians to radians

it returns: x * pi / 200

template<class ValueType >
ValueType ttmath::Ln ( const ValueType &  x,
ErrorCode *  err = 0 
)

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

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

this function calculates the logarithm

template<class ValueType >
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

template<class ValueType >
ValueType ttmath::RadToDeg ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts radians to degrees

it returns: x * 180 / pi

template<class ValueType >
ValueType ttmath::RadToGrad ( const ValueType &  x,
ErrorCode *  err = 0 
)

this function converts radians to gradians

it returns: x * 200 / pi

template<class ValueType >
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)

template<class ValueType >
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

template<class ValueType >
ValueType ttmath::Sgn ( ValueType  x)

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

template<class ValueType >
ValueType ttmath::Sin ( ValueType  x,
ErrorCode *  err = 0 
)

this function calculates the Sine

template<class ValueType >
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

template<class ValueType >
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

template<class ValueType >
ValueType ttmath::Sqrt ( ValueType  x,
ErrorCode *  err = 0 
)

this function calculates the square root

Sqrt(9) = 3

template<class ValueType >
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'

template<class ValueType >
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) )

template<class ValueType >
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)

template<class ValueType >
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)