TTMath  0.9.4
 C++ bignum library
Data Structures | Typedefs | Enumerations | Functions | Variables
ttmath Namespace Reference

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
 

Detailed Description

a namespace for the TTMath library

Typedef Documentation

§ sint

typedef signed long ttmath::sint

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

Definition at line 243 of file ttmathtypes.h.

§ uint

typedef unsigned long ttmath::uint

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

Definition at line 238 of file ttmathtypes.h.

Enumeration Type Documentation

§ ErrorCode

error codes

Definition at line 370 of file ttmathtypes.h.

371  {
372  err_ok = 0,
373  err_nothing_has_read,
374  err_unknown_character,
375  err_unexpected_final_bracket,
376  err_stack_not_clear,
377  err_unknown_variable,
378  err_division_by_zero,
379  err_interrupt,
380  err_overflow,
381  err_unknown_function,
382  err_unknown_operator,
383  err_unexpected_semicolon_operator,
384  err_improper_amount_of_arguments,
385  err_improper_argument,
386  err_unexpected_end,
387  err_internal_error,
388  err_incorrect_name,
389  err_incorrect_value,
390  err_variable_exists,
391  err_variable_loop,
392  err_functions_loop,
393  err_must_be_only_one_value,
394  err_object_exists,
395  err_unknown_object,
396  err_still_calculating,
397  err_in_short_form_used_function,
398  err_percent_from
399  };

§ LibTypeCode

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 356 of file ttmathtypes.h.

357  {
358  asm_vc_32 = 0,
359  asm_gcc_32,
360  asm_vc_64,
361  asm_gcc_64,
362  no_asm_32,
363  no_asm_64
364  };

Function Documentation

§ Abs()

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

absolute value of x

samples:

  • -2 = 2
  • 2 = 2

Definition at line 2137 of file ttmath.h.

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

2138  {
2139  ValueType result( x );
2140  result.Abs();
2141 
2142  return result;
2143  }

§ ACos()

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)

Definition at line 910 of file ttmath.h.

References ASin().

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

911  {
912  ValueType temp;
913 
914  temp.Set05Pi();
915  temp.Sub(ASin(x, err));
916 
917  return temp;
918  }
ValueType ASin(ValueType x, ErrorCode *err=0)
Definition: ttmath.h:855

§ ACosh()

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)

Definition at line 1387 of file ttmath.h.

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

1388  {
1389  if( x.IsNan() )
1390  {
1391  if( err )
1392  *err = err_improper_argument;
1393 
1394  return x; // NaN
1395  }
1396 
1397  ValueType xx(x), one, result;
1398  uint c = 0;
1399  one.SetOne();
1400 
1401  if( x < one )
1402  {
1403  if( err )
1404  *err = err_improper_argument;
1405 
1406  return result; // NaN is set by default
1407  }
1408 
1409  c += xx.Mul(x);
1410  c += xx.Sub(one);
1411  // xx is >= 0
1412  // we can't call a PowFrac when the 'x' is zero
1413  // if x is 0 the sqrt(0) is 0
1414  if( !xx.IsZero() )
1415  {
1416  one.exponent.SubOne(); // one=0.5
1417  c += xx.PowFrac(one); // xx=sqrt(xx)
1418  }
1419  c += xx.Add(x);
1420  c += result.Ln(xx); // xx >= 1
1421 
1422  // here can only be a carry
1423  if( err )
1424  *err = c ? err_overflow : err_ok;
1425 
1426  return result;
1427  }
unsigned long uint
Definition: ttmathtypes.h:238

§ ACot()

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)

Definition at line 1136 of file ttmath.h.

References ATan().

Referenced by ACtg(), and ttmath::Parser< ValueType >::GetValueOfVariable().

1137  {
1138  ValueType result;
1139 
1140  result.Set05Pi();
1141  result.Sub(ATan(x));
1142 
1143  return result;
1144  }
ValueType ATan(ValueType x)
Definition: ttmath.h:1085

§ ACoth()

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)

Definition at line 1489 of file ttmath.h.

Referenced by ACtgh(), and ttmath::Parser< ValueType >::GetValueOfVariable().

1490  {
1491  if( x.IsNan() )
1492  {
1493  if( err )
1494  *err = err_improper_argument;
1495 
1496  return x; // NaN
1497  }
1498 
1499  ValueType nominator(x), denominator(x), one, result;
1500  uint c = 0;
1501  one.SetOne();
1502 
1503  if( !x.GreaterWithoutSignThan(one) )
1504  {
1505  if( err )
1506  *err = err_improper_argument;
1507 
1508  return result; // NaN is set by default
1509  }
1510 
1511  c += nominator.Add(one);
1512  c += denominator.Sub(one);
1513  c += nominator.Div(denominator);
1514  c += result.Ln(nominator);
1515  c += result.exponent.SubOne();
1516 
1517  // here can only be a carry
1518  if( err )
1519  *err = c ? err_overflow : err_ok;
1520 
1521  return result;
1522  }
unsigned long uint
Definition: ttmathtypes.h:238

§ ACtg()

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)

Definition at line 1154 of file ttmath.h.

References ACot().

1155  {
1156  return ACot(x);
1157  }
ValueType ACot(const ValueType &x)
Definition: ttmath.h:1136

§ ACtgh()

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

inverse hyperbolic cotantent

Definition at line 1529 of file ttmath.h.

References ACoth().

1530  {
1531  return ACoth(x, err);
1532  }
ValueType ACoth(const ValueType &x, ErrorCode *err=0)
Definition: ttmath.h:1489

§ ASin()

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

856  {
857  using namespace auxiliaryfunctions;
858 
859  ValueType result, one;
860  one.SetOne();
861  bool change_sign = false;
862 
863  if( x.IsNan() )
864  {
865  if( err )
866  *err = err_improper_argument;
867 
868  return x;
869  }
870 
871  if( x.GreaterWithoutSignThan(one) )
872  {
873  if( err )
874  *err = err_improper_argument;
875 
876  return result; // NaN is set by default
877  }
878 
879  if( x.IsSign() )
880  {
881  change_sign = true;
882  x.Abs();
883  }
884 
885  one.exponent.SubOne(); // =0.5
886 
887  // asin(-x) = -asin(x)
888  if( x.GreaterWithoutSignThan(one) )
889  result = ASin_1(x);
890  else
891  result = ASin_0(x);
892 
893  if( change_sign )
894  result.ChangeSign();
895 
896  if( err )
897  *err = err_ok;
898 
899  return result;
900  }

§ ASinh()

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

1352  {
1353  if( x.IsNan() )
1354  {
1355  if( err )
1356  *err = err_improper_argument;
1357 
1358  return x; // NaN
1359  }
1360 
1361  ValueType xx(x), one, result;
1362  uint c = 0;
1363  one.SetOne();
1364 
1365  c += xx.Mul(x);
1366  c += xx.Add(one);
1367  one.exponent.SubOne(); // one=0.5
1368  // xx is >= 1
1369  c += xx.PowFrac(one); // xx=sqrt(xx)
1370  c += xx.Add(x);
1371  c += result.Ln(xx); // xx > 0
1372 
1373  // here can only be a carry
1374  if( err )
1375  *err = c ? err_overflow : err_ok;
1376 
1377  return result;
1378  }
unsigned long uint
Definition: ttmathtypes.h:238

§ ATan()

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

1086  {
1087  using namespace auxiliaryfunctions;
1088 
1089  ValueType one, result;
1090  one.SetOne();
1091  bool change_sign = false;
1092 
1093  if( x.IsNan() )
1094  return x;
1095 
1096  // if x is negative we're using the formula:
1097  // atan(-x) = -atan(x)
1098  if( x.IsSign() )
1099  {
1100  change_sign = true;
1101  x.Abs();
1102  }
1103 
1104  if( x.GreaterWithoutSignThan(one) )
1105  result = ATanGreaterThanPlusOne(x);
1106  else
1107  result = ATan01(x);
1108 
1109  if( change_sign )
1110  result.ChangeSign();
1111 
1112  return result;
1113  }

§ ATanh()

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)

Definition at line 1436 of file ttmath.h.

Referenced by ATgh(), and ttmath::Parser< ValueType >::GetValueOfVariable().

1437  {
1438  if( x.IsNan() )
1439  {
1440  if( err )
1441  *err = err_improper_argument;
1442 
1443  return x; // NaN
1444  }
1445 
1446  ValueType nominator(x), denominator, one, result;
1447  uint c = 0;
1448  one.SetOne();
1449 
1450  if( !x.SmallerWithoutSignThan(one) )
1451  {
1452  if( err )
1453  *err = err_improper_argument;
1454 
1455  return result; // NaN is set by default
1456  }
1457 
1458  c += nominator.Add(one);
1459  denominator = one;
1460  c += denominator.Sub(x);
1461  c += nominator.Div(denominator);
1462  c += result.Ln(nominator);
1463  c += result.exponent.SubOne();
1464 
1465  // here can only be a carry
1466  if( err )
1467  *err = c ? err_overflow : err_ok;
1468 
1469  return result;
1470  }
unsigned long uint
Definition: ttmathtypes.h:238

§ ATg()

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)

Definition at line 1123 of file ttmath.h.

References ATan().

1124  {
1125  return ATan(x);
1126  }
ValueType ATan(ValueType x)
Definition: ttmath.h:1085

§ ATgh()

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

inverse hyperbolic tantent

Definition at line 1477 of file ttmath.h.

References ATanh().

1478  {
1479  return ATanh(x, err);
1480  }
ValueType ATanh(const ValueType &x, ErrorCode *err=0)
Definition: ttmath.h:1436

§ Ceil()

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

Definition at line 142 of file ttmath.h.

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

143  {
144  if( x.IsNan() )
145  {
146  if( err )
147  *err = err_improper_argument;
148 
149  return x; // NaN
150  }
151 
152  ValueType result(x);
153  uint c = 0;
154 
155  result.SkipFraction();
156 
157  if( result != x )
158  {
159  // x is with fraction
160  // if x is negative we don't have to do anything
161  if( !x.IsSign() )
162  {
163  ValueType one;
164  one.SetOne();
165 
166  c += result.Add(one);
167  }
168  }
169 
170  if( err )
171  *err = c ? err_overflow : err_ok;
172 
173  return result;
174  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Cos()

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)

Definition at line 581 of file ttmath.h.

References Sin().

Referenced by Cot(), ttmath::Parser< ValueType >::GetValueOfVariable(), and Tan().

582  {
583  if( x.IsNan() )
584  {
585  if( err )
586  *err = err_improper_argument;
587 
588  return x; // NaN
589  }
590 
591  ValueType pi05;
592  pi05.Set05Pi();
593 
594  uint c = x.Add( pi05 );
595 
596  if( c )
597  {
598  if( err )
599  *err = err_overflow;
600 
601  return ValueType(); // result is undefined (NaN is set by default)
602  }
603 
604  return Sin(x, err);
605  }
ValueType Sin(ValueType x, ErrorCode *err=0)
Definition: ttmath.h:525
unsigned long uint
Definition: ttmathtypes.h:238

§ Cosh()

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

Definition at line 1206 of file ttmath.h.

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

1207  {
1208  if( x.IsNan() )
1209  {
1210  if( err )
1211  *err = err_improper_argument;
1212 
1213  return x; // NaN
1214  }
1215 
1216  ValueType ex, emx;
1217  uint c = 0;
1218 
1219  c += ex.Exp(x);
1220  c += emx.Exp(-x);
1221 
1222  c += ex.Add(emx);
1223  c += ex.exponent.SubOne();
1224 
1225  if( err )
1226  *err = c ? err_overflow : err_ok;
1227 
1228  return ex;
1229  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Cot()

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)

Definition at line 661 of file ttmath.h.

References Cos(), and Sin().

Referenced by Ctg(), and ttmath::Parser< ValueType >::GetValueOfVariable().

662  {
663  ValueType result = Sin(x, err);
664 
665  if( err && *err != err_ok )
666  return result;
667 
668  if( result.IsZero() )
669  {
670  if( err )
671  *err = err_improper_argument;
672 
673  result.SetNan();
674 
675  return result;
676  }
677 
678  return Cos(x, err) / result;
679  }
ValueType Sin(ValueType x, ErrorCode *err=0)
Definition: ttmath.h:525
ValueType Cos(ValueType x, ErrorCode *err=0)
Definition: ttmath.h:581

§ Coth()

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) )

Definition at line 1286 of file ttmath.h.

Referenced by Ctgh(), and ttmath::Parser< ValueType >::GetValueOfVariable().

1287  {
1288  if( x.IsNan() )
1289  {
1290  if( err )
1291  *err = err_improper_argument;
1292 
1293  return x; // NaN
1294  }
1295 
1296  if( x.IsZero() )
1297  {
1298  if( err )
1299  *err = err_improper_argument;
1300 
1301  return ValueType(); // NaN is set by default
1302  }
1303 
1304  ValueType ex, emx, nominator, denominator;
1305  uint c = 0;
1306 
1307  c += ex.Exp(x);
1308  c += emx.Exp(-x);
1309 
1310  nominator = ex;
1311  c += nominator.Add(emx);
1312  denominator = ex;
1313  c += denominator.Sub(emx);
1314 
1315  c += nominator.Div(denominator);
1316 
1317  if( err )
1318  *err = c ? err_overflow : err_ok;
1319 
1320  return nominator;
1321  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Ctg()

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)

Definition at line 689 of file ttmath.h.

References Cot().

690  {
691  return Cot(x, err);
692  }
ValueType Cot(const ValueType &x, ErrorCode *err=0)
Definition: ttmath.h:661

§ Ctgh()

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)

Definition at line 1331 of file ttmath.h.

References Coth().

1332  {
1333  return Coth(x, err);
1334  }
ValueType Coth(const ValueType &x, ErrorCode *err=0)
Definition: ttmath.h:1286

§ DegToDeg()

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)

samples:

  • DegToDeg(10, 30, 0) = 10.5
  • DegToDeg(10, 24, 35.6)=10.4098(8)

Definition at line 1633 of file ttmath.h.

Referenced by DegToGrad(), DegToRad(), and ttmath::Parser< ValueType >::GetValueOfVariable().

1635  {
1636  ValueType delimiter, multipler;
1637  uint c = 0;
1638 
1639  if( d.IsNan() || m.IsNan() || s.IsNan() || m.IsSign() || s.IsSign() )
1640  {
1641  if( err )
1642  *err = err_improper_argument;
1643 
1644  delimiter.SetZeroNan(); // not needed, only to get rid of GCC warning about an uninitialized variable
1645 
1646  return delimiter;
1647  }
1648 
1649  multipler = 60;
1650  delimiter = 3600;
1651 
1652  c += multipler.Mul(m);
1653  c += multipler.Add(s);
1654  c += multipler.Div(delimiter);
1655 
1656  if( d.IsSign() )
1657  multipler.ChangeSign();
1658 
1659  c += multipler.Add(d);
1660 
1661  if( err )
1662  *err = c ? err_overflow : err_ok;
1663 
1664  return multipler;
1665  }
unsigned long uint
Definition: ttmathtypes.h:238

§ DegToGrad() [1/2]

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

1759  {
1760  ValueType result, temp;
1761  uint c = 0;
1762 
1763  if( x.IsNan() )
1764  {
1765  if( err )
1766  *err = err_improper_argument;
1767 
1768  return x;
1769  }
1770 
1771  result = x;
1772 
1773  temp = 200;
1774  c += result.Mul(temp);
1775 
1776  temp = 180;
1777  c += result.Div(temp);
1778 
1779  if( err )
1780  *err = c ? err_overflow : err_ok;
1781 
1782  return result;
1783  }
unsigned long uint
Definition: ttmathtypes.h:238

§ DegToGrad() [2/2]

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

Definition at line 1790 of file ttmath.h.

References DegToDeg(), and DegToGrad().

1792  {
1793  ValueType temp_deg = DegToDeg(d,m,s,err);
1794 
1795  if( err && *err!=err_ok )
1796  return temp_deg;
1797 
1798  return DegToGrad(temp_deg, err);
1799  }
ValueType DegToGrad(const ValueType &d, const ValueType &m, const ValueType &s, ErrorCode *err=0)
Definition: ttmath.h:1790
ValueType DegToDeg(const ValueType &d, const ValueType &m, const ValueType &s, ErrorCode *err=0)
Definition: ttmath.h:1633

§ DegToRad() [1/2]

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

1553  {
1554  ValueType result, temp;
1555  uint c = 0;
1556 
1557  if( x.IsNan() )
1558  {
1559  if( err )
1560  *err = err_improper_argument;
1561 
1562  return x;
1563  }
1564 
1565  result = x;
1566 
1567  // it is better to make division first and then multiplication
1568  // the result is more accurate especially when x is: 90,180,270 or 360
1569  temp = 180;
1570  c += result.Div(temp);
1571 
1572  temp.SetPi();
1573  c += result.Mul(temp);
1574 
1575  if( err )
1576  *err = c ? err_overflow : err_ok;
1577 
1578  return result;
1579  }
unsigned long uint
Definition: ttmathtypes.h:238

§ DegToRad() [2/2]

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

Definition at line 1672 of file ttmath.h.

References DegToDeg(), and DegToRad().

1674  {
1675  ValueType temp_deg = DegToDeg(d,m,s,err);
1676 
1677  if( err && *err!=err_ok )
1678  return temp_deg;
1679 
1680  return DegToRad(temp_deg, err);
1681  }
ValueType DegToDeg(const ValueType &d, const ValueType &m, const ValueType &s, ErrorCode *err=0)
Definition: ttmath.h:1633
ValueType DegToRad(const ValueType &d, const ValueType &m, const ValueType &s, ErrorCode *err=0)
Definition: ttmath.h:1672

§ Exp()

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

324  {
325  if( x.IsNan() )
326  {
327  if( err )
328  *err = err_improper_argument;
329 
330  return x; // NaN
331  }
332 
333  ValueType result;
334  uint c = result.Exp(x);
335 
336  if( err )
337  *err = c ? err_overflow : err_ok;
338 
339  return result;
340  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Factorial() [1/2]

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

Definition at line 2809 of file ttmath.h.

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

2811  {
2812  return auxiliaryfunctions::Factorial2(x, &cgamma, err, stop);
2813  }

§ Factorial() [2/2]

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

Definition at line 2824 of file ttmath.h.

2825  {
2826  return auxiliaryfunctions::Factorial2(x, (CGamma<ValueType>*)0, err, 0);
2827  }

§ Floor()

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

Definition at line 189 of file ttmath.h.

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

190  {
191  if( x.IsNan() )
192  {
193  if( err )
194  *err = err_improper_argument;
195 
196  return x; // NaN
197  }
198 
199  ValueType result(x);
200  uint c = 0;
201 
202  result.SkipFraction();
203 
204  if( result != x )
205  {
206  // x is with fraction
207  // if x is positive we don't have to do anything
208  if( x.IsSign() )
209  {
210  ValueType one;
211  one.SetOne();
212 
213  c += result.Sub(one);
214  }
215  }
216 
217  if( err )
218  *err = c ? err_overflow : err_ok;
219 
220  return result;
221  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Gamma() [1/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

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().

2681  {
2682  using namespace auxiliaryfunctions;
2683 
2684  ValueType result;
2685  ErrorCode err_tmp;
2686 
2687  if( n.IsNan() )
2688  {
2689  if( err )
2690  *err = err_improper_argument;
2691 
2692  return n;
2693  }
2694 
2695  if( cgamma.history.Get(n, result, err_tmp) )
2696  {
2697  if( err )
2698  *err = err_tmp;
2699 
2700  return result;
2701  }
2702 
2703  err_tmp = err_ok;
2704 
2705  if( n.IsSign() )
2706  {
2707  result = GammaMinus(n, cgamma, err_tmp, stop);
2708  }
2709  else
2710  if( n.IsZero() )
2711  {
2712  err_tmp = err_improper_argument;
2713  result.SetNan();
2714  }
2715  else
2716  {
2717  result = GammaPlus(n, cgamma, err_tmp, stop);
2718  }
2719 
2720  if( result.IsNan() && err_tmp==err_ok )
2721  err_tmp = err_overflow;
2722 
2723  if( err )
2724  *err = err_tmp;
2725 
2726  if( stop && !stop->WasStopSignal() )
2727  cgamma.history.Add(n, result, err_tmp);
2728 
2729  return result;
2730  }

§ Gamma() [2/2]

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

Definition at line 2739 of file ttmath.h.

References Gamma().

2740  {
2741  // warning: this static object is not thread safe
2742  static CGamma<ValueType> cgamma;
2743 
2744  return Gamma(n, cgamma, err);
2745  }
ValueType Gamma(const ValueType &n, ErrorCode *err=0)
Definition: ttmath.h:2739

§ GradToDeg()

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

1809  {
1810  ValueType result, temp;
1811  uint c = 0;
1812 
1813  if( x.IsNan() )
1814  {
1815  if( err )
1816  *err = err_improper_argument;
1817 
1818  return x;
1819  }
1820 
1821  result = x;
1822 
1823  temp = 180;
1824  c += result.Mul(temp);
1825 
1826  temp = 200;
1827  c += result.Div(temp);
1828 
1829  if( err )
1830  *err = c ? err_overflow : err_ok;
1831 
1832  return result;
1833  }
unsigned long uint
Definition: ttmathtypes.h:238

§ GradToRad()

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

1691  {
1692  ValueType result, temp;
1693  uint c = 0;
1694 
1695  if( x.IsNan() )
1696  {
1697  if( err )
1698  *err = err_improper_argument;
1699 
1700  return x;
1701  }
1702 
1703  result = x;
1704 
1705  // it is better to make division first and then multiplication
1706  // the result is more accurate especially when x is: 100,200,300 or 400
1707  temp = 200;
1708  c += result.Div(temp);
1709 
1710  temp.SetPi();
1711  c += result.Mul(temp);
1712 
1713  if( err )
1714  *err = c ? err_overflow : err_ok;
1715 
1716  return result;
1717  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Ln()

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

238  {
239  if( x.IsNan() )
240  {
241  if( err )
242  *err = err_improper_argument;
243 
244  return x; // NaN
245  }
246 
247  ValueType result;
248  uint state = result.Ln(x);
249 
250  if( err )
251  {
252  switch( state )
253  {
254  case 0:
255  *err = err_ok;
256  break;
257  case 1:
258  *err = err_overflow;
259  break;
260  case 2:
261  *err = err_improper_argument;
262  break;
263  default:
264  *err = err_internal_error;
265  break;
266  }
267  }
268 
269 
270  return result;
271  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Log()

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

279  {
280  if( x.IsNan() )
281  {
282  if( err ) *err = err_improper_argument;
283  return x;
284  }
285 
286  if( base.IsNan() )
287  {
288  if( err ) *err = err_improper_argument;
289  return base;
290  }
291 
292  ValueType result;
293  uint state = result.Log(x, base);
294 
295  if( err )
296  {
297  switch( state )
298  {
299  case 0:
300  *err = err_ok;
301  break;
302  case 1:
303  *err = err_overflow;
304  break;
305  case 2:
306  case 3:
307  *err = err_improper_argument;
308  break;
309  default:
310  *err = err_internal_error;
311  break;
312  }
313  }
314 
315  return result;
316  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Mod()

template<class ValueType >
ValueType ttmath::Mod ( ValueType  a,
const ValueType &  b,
ErrorCode err = 0 
)

the remainder from a division

samples:

  • 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 2173 of file ttmath.h.

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

2174  {
2175  if( a.IsNan() || b.IsNan() )
2176  {
2177  if( err )
2178  *err = err_improper_argument;
2179 
2180  a.SetNan();
2181 
2182  return a;
2183  }
2184 
2185  uint c = a.Mod(b);
2186 
2187  if( err )
2188  *err = c ? err_overflow : err_ok;
2189 
2190  return a;
2191  }
unsigned long uint
Definition: ttmathtypes.h:238

§ RadToDeg()

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

1589  {
1590  ValueType result, delimiter;
1591  uint c = 0;
1592 
1593  if( x.IsNan() )
1594  {
1595  if( err )
1596  *err = err_improper_argument;
1597 
1598  return x;
1599  }
1600 
1601  result = 180;
1602  c += result.Mul(x);
1603 
1604  delimiter.SetPi();
1605  c += result.Div(delimiter);
1606 
1607  if( err )
1608  *err = c ? err_overflow : err_ok;
1609 
1610  return result;
1611  }
unsigned long uint
Definition: ttmathtypes.h:238

§ RadToGrad()

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

1727  {
1728  ValueType result, delimiter;
1729  uint c = 0;
1730 
1731  if( x.IsNan() )
1732  {
1733  if( err )
1734  *err = err_improper_argument;
1735 
1736  return x;
1737  }
1738 
1739  result = 200;
1740  c += result.Mul(x);
1741 
1742  delimiter.SetPi();
1743  c += result.Div(delimiter);
1744 
1745  if( err )
1746  *err = c ? err_overflow : err_ok;
1747 
1748  return result;
1749  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Root()

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

  • 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 2076 of file ttmath.h.

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

2077  {
2078  using namespace auxiliaryfunctions;
2079 
2080  if( x.IsNan() || index.IsNan() )
2081  {
2082  if( err )
2083  *err = err_improper_argument;
2084 
2085  x.SetNan();
2086 
2087  return x;
2088  }
2089 
2090  if( RootCheckIndexSign(x, index, err) ) return x;
2091  if( RootCheckIndexZero(x, index, err) ) return x;
2092  if( RootCheckIndexOne ( index, err) ) return x;
2093  if( RootCheckIndexTwo (x, index, err) ) return x;
2094  if( RootCheckIndexFrac(x, index, err) ) return x;
2095  if( RootCheckXZero (x, err) ) return x;
2096 
2097  // index integer and index!=0
2098  // x!=0
2099 
2100  ValueType old_x(x);
2101  bool change_sign;
2102 
2103  if( RootCheckIndex(x, index, err, &change_sign ) ) return x;
2104 
2105  ValueType temp;
2106  uint c = 0;
2107 
2108  // we're using the formula: root(x ; n) = exp( ln(x) / n )
2109  c += temp.Ln(x);
2110  c += temp.Div(index);
2111  c += x.Exp(temp);
2112 
2113  if( change_sign )
2114  {
2115  // x is different from zero
2116  x.SetSign();
2117  }
2118 
2119  c += RootCorrectInteger(old_x, x, index);
2120 
2121  if( err )
2122  *err = c ? err_overflow : err_ok;
2123 
2124  return x;
2125  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Round()

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

this function rounds to the nearest integer value

samples

  • 2.2 = 2
  • 2.7 = 3
  • -2.2 = -2
  • -2.7 = -3

Definition at line 109 of file ttmath.h.

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

110  {
111  if( x.IsNan() )
112  {
113  if( err )
114  *err = err_improper_argument;
115 
116  return x; // NaN
117  }
118 
119  ValueType result( x );
120  uint c = result.Round();
121 
122  if( err )
123  *err = c ? err_overflow : err_ok;
124 
125  return result;
126  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Sgn()

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

it returns the sign of the value

samples:

  • -2 = -1
  • 0 = 0
  • 10 = 1

Definition at line 2155 of file ttmath.h.

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

2156  {
2157  x.Sgn();
2158 
2159  return x;
2160  }

§ Sin()

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

this function calculates the Sine

Definition at line 525 of file ttmath.h.

Referenced by Cos(), Cot(), ttmath::Parser< ValueType >::GetValueOfVariable(), and Tan().

526  {
527  using namespace auxiliaryfunctions;
528 
529  ValueType one, result;
530  bool change_sign;
531 
532  if( x.IsNan() )
533  {
534  if( err )
535  *err = err_improper_argument;
536 
537  return x;
538  }
539 
540  if( err )
541  *err = err_ok;
542 
543  if( PrepareSin( x, change_sign ) )
544  {
545  // x is too big, we cannnot reduce the 2*PI period
546  // prior to version 0.8.5 the result was zero
547 
548  // result has NaN flag set by default
549 
550  if( err )
551  *err = err_overflow; // maybe another error code? err_improper_argument?
552 
553  return result; // NaN is set by default
554  }
555 
556  result = Sin0pi05( x );
557 
558  one.SetOne();
559 
560  // after calculations there can be small distortions in the result
561  if( result > one )
562  result = one;
563  else
564  if( result.IsSign() )
565  // we've calculated the sin from <0, pi/2> and the result
566  // should be positive
567  result.SetZero();
568 
569  if( change_sign )
570  result.ChangeSign();
571 
572  return result;
573  }

§ Sinh()

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

Definition at line 1174 of file ttmath.h.

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

1175  {
1176  if( x.IsNan() )
1177  {
1178  if( err )
1179  *err = err_improper_argument;
1180 
1181  return x; // NaN
1182  }
1183 
1184  ValueType ex, emx;
1185  uint c = 0;
1186 
1187  c += ex.Exp(x);
1188  c += emx.Exp(-x);
1189 
1190  c += ex.Sub(emx);
1191  c += ex.exponent.SubOne();
1192 
1193  if( err )
1194  *err = c ? err_overflow : err_ok;
1195 
1196  return ex;
1197  }
unsigned long uint
Definition: ttmathtypes.h:238

§ SkipFraction()

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

this function skips the fraction from x

samples

  • 2.2 = 2
  • 2.7 = 2
  • -2.2 = 2
  • -2.7 = 2

Definition at line 90 of file ttmath.h.

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

91  {
92  ValueType result( x );
93  result.SkipFraction();
94 
95  return result;
96  }

§ Sqrt()

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

1853  {
1854  if( x.IsNan() || x.IsSign() )
1855  {
1856  if( err )
1857  *err = err_improper_argument;
1858 
1859  x.SetNan();
1860 
1861  return x;
1862  }
1863 
1864  uint c = x.Sqrt();
1865 
1866  if( err )
1867  *err = c ? err_overflow : err_ok;
1868 
1869  return x;
1870  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Tan()

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'

Definition at line 619 of file ttmath.h.

References Cos(), and Sin().

Referenced by ttmath::Parser< ValueType >::GetValueOfVariable(), and Tg().

620  {
621  ValueType result = Cos(x, err);
622 
623  if( err && *err != err_ok )
624  return result;
625 
626  if( result.IsZero() )
627  {
628  if( err )
629  *err = err_improper_argument;
630 
631  result.SetNan();
632 
633  return result;
634  }
635 
636  return Sin(x, err) / result;
637  }
ValueType Sin(ValueType x, ErrorCode *err=0)
Definition: ttmath.h:525
ValueType Cos(ValueType x, ErrorCode *err=0)
Definition: ttmath.h:581

§ Tanh()

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) )

Definition at line 1238 of file ttmath.h.

Referenced by ttmath::Parser< ValueType >::GetValueOfVariable(), and Tgh().

1239  {
1240  if( x.IsNan() )
1241  {
1242  if( err )
1243  *err = err_improper_argument;
1244 
1245  return x; // NaN
1246  }
1247 
1248  ValueType ex, emx, nominator, denominator;
1249  uint c = 0;
1250 
1251  c += ex.Exp(x);
1252  c += emx.Exp(-x);
1253 
1254  nominator = ex;
1255  c += nominator.Sub(emx);
1256  denominator = ex;
1257  c += denominator.Add(emx);
1258 
1259  c += nominator.Div(denominator);
1260 
1261  if( err )
1262  *err = c ? err_overflow : err_ok;
1263 
1264  return nominator;
1265  }
unsigned long uint
Definition: ttmathtypes.h:238

§ Tg()

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)

Definition at line 647 of file ttmath.h.

References Tan().

648  {
649  return Tan(x, err);
650  }
ValueType Tan(const ValueType &x, ErrorCode *err=0)
Definition: ttmath.h:619

§ Tgh()

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)

Definition at line 1275 of file ttmath.h.

References Tanh().

1276  {
1277  return Tanh(x, err);
1278  }
ValueType Tanh(const ValueType &x, ErrorCode *err=0)
Definition: ttmath.h:1238

Variable Documentation

§ ttmath_mutex

pthread_mutex_t ttmath::ttmath_mutex

ttmath_mutex will be defined by TTMATH_MULTITHREADS_HELPER macro