![]() |
TTMath
0.9.4
C++ bignum library
|
a namespace for the TTMath library More...
Data Structures | |
class | Big |
Big implements the floating point numbers. More... | |
struct | CGamma |
struct | Conv |
class | ExceptionInfo |
class | History |
class | Int |
Int implements a big integer value with a sign. More... | |
class | Misc |
class | Objects |
class | Parser |
Mathematical parser. More... | |
class | ReferenceError |
class | RuntimeError |
class | StopCalculating |
class | ThreadLock |
objects of this class are used to synchronize More... | |
class | UInt |
UInt implements a big integer value without a sign. More... | |
class | UInt< 0 > |
Typedefs | |
typedef unsigned long | uint |
typedef signed long | sint |
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) |
Variables | |
pthread_mutex_t | ttmath_mutex |
a namespace for the TTMath library
typedef signed long ttmath::sint |
on 64bit platforms one word (uint, sint) will be equal 64bits
Definition at line 243 of file ttmathtypes.h.
typedef unsigned long ttmath::uint |
on 64bit platforms one word (uint, sint) will be equal 64bits
Definition at line 238 of file ttmathtypes.h.
enum ttmath::ErrorCode |
enum ttmath::LibTypeCode |
lib type codes:
Definition at line 356 of file ttmathtypes.h.
ValueType ttmath::Abs | ( | const ValueType & | x | ) |
absolute value of x
samples:
Definition at line 2137 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
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 910 of file ttmath.h.
References ASin().
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
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 1387 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
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 1136 of file ttmath.h.
References ATan().
Referenced by ACtg(), and ttmath::Parser< ValueType >::GetValueOfVariable().
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 1489 of file ttmath.h.
Referenced by ACtgh(), and ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::ACtg | ( | const ValueType & | x | ) |
ValueType ttmath::ACtgh | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
ValueType ttmath::ASin | ( | ValueType | x, |
ErrorCode * | err = 0 |
||
) |
this function calculates the Arc Sine x is from <-1,1>
Definition at line 855 of file ttmath.h.
Referenced by ACos(), and ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::ASinh | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
inverse hyperbolic sine
asinh(x) = ln( x + sqrt(x^2 + 1) )
Definition at line 1351 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::ATan | ( | ValueType | x | ) |
this function calculates the Arc Tangent
Definition at line 1085 of file ttmath.h.
Referenced by ACot(), ATg(), and ttmath::Parser< ValueType >::GetValueOfVariable().
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 1436 of file ttmath.h.
Referenced by ATgh(), and ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::ATg | ( | const ValueType & | x | ) |
ValueType ttmath::ATgh | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
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
Definition at line 142 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Cos | ( | ValueType | x, |
ErrorCode * | err = 0 |
||
) |
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 1206 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
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 661 of file ttmath.h.
Referenced by Ctg(), and ttmath::Parser< ValueType >::GetValueOfVariable().
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 1286 of file ttmath.h.
Referenced by Ctgh(), and ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Ctg | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
ValueType ttmath::Ctgh | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
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:
((s/60)+m)/60 = (s+60*m)/3600 (second version is faster because there's only one division)
samples:
Definition at line 1633 of file ttmath.h.
Referenced by DegToGrad(), DegToRad(), and ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::DegToGrad | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function converts degrees to gradians
it returns: x * 200 / 180
Definition at line 1758 of file ttmath.h.
Referenced by DegToGrad(), and ttmath::Parser< ValueType >::GetValueOfVariable().
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 1790 of file ttmath.h.
References DegToDeg(), and DegToGrad().
ValueType ttmath::DegToRad | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function converts degrees to radians
it returns: x * pi / 180
Definition at line 1552 of file ttmath.h.
Referenced by DegToRad(), and ttmath::Parser< ValueType >::GetValueOfVariable().
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 1672 of file ttmath.h.
References DegToDeg(), and DegToRad().
ValueType ttmath::Exp | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function calculates the expression e^x
Definition at line 323 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
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 2809 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Factorial | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
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
Definition at line 189 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
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 2679 of file ttmath.h.
References ttmath::CGamma< ValueType >::history.
Referenced by Gamma(), ttmath::Parser< ValueType >::GetValueOfVariable(), and ttmath::CGamma< ValueType >::InitAll().
ValueType ttmath::Gamma | ( | const ValueType & | n, |
ErrorCode * | err = 0 |
||
) |
ValueType ttmath::GradToDeg | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function converts degrees to gradians
it returns: x * 180 / 200
Definition at line 1808 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::GradToRad | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function converts gradians to radians
it returns: x * pi / 200
Definition at line 1690 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Ln | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function calculates the natural logarithm (logarithm with the base 'e')
Definition at line 237 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Log | ( | const ValueType & | x, |
const ValueType & | base, | ||
ErrorCode * | err = 0 |
||
) |
this function calculates the logarithm
Definition at line 278 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Mod | ( | ValueType | a, |
const ValueType & | b, | ||
ErrorCode * | err = 0 |
||
) |
the remainder from a division
samples:
Definition at line 2173 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::RadToDeg | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function converts radians to degrees
it returns: x * 180 / pi
Definition at line 1588 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::RadToGrad | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function converts radians to gradians
it returns: x * 200 / pi
Definition at line 1726 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Root | ( | ValueType | x, |
const ValueType & | index, | ||
ErrorCode * | err = 0 |
||
) |
caltulate the index'th Root of x
index must be integer and not negative <0;1;2;3....)
Definition at line 2076 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Round | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
this function rounds to the nearest integer value
samples
Definition at line 109 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Sgn | ( | ValueType | x | ) |
it returns the sign of the value
samples:
Definition at line 2155 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Sin | ( | ValueType | x, |
ErrorCode * | err = 0 |
||
) |
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 1174 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::SkipFraction | ( | const ValueType & | x | ) |
this function skips the fraction from x
samples
Definition at line 90 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
ValueType ttmath::Sqrt | ( | ValueType | x, |
ErrorCode * | err = 0 |
||
) |
this function calculates the square root
Sqrt(9) = 3
Definition at line 1852 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable().
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 619 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable(), and Tg().
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 1238 of file ttmath.h.
Referenced by ttmath::Parser< ValueType >::GetValueOfVariable(), and Tgh().
ValueType ttmath::Tg | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
ValueType ttmath::Tgh | ( | const ValueType & | x, |
ErrorCode * | err = 0 |
||
) |
pthread_mutex_t ttmath::ttmath_mutex |
ttmath_mutex will be defined by TTMATH_MULTITHREADS_HELPER macro