TTMath  0.9.4
 C++ bignum library
Public Member Functions | Static Public Member Functions | Data Fields | Friends
ttmath::Big< exp, man > Class Template Reference

Big implements the floating point numbers. More...

#include <ttmathbig.h>

Collaboration diagram for ttmath::Big< exp, man >:
Collaboration graph
[legend]

Public Member Functions

uint CheckCarry (uint c)
 
uint Standardizing ()
 
void ClearInfoBit (unsigned char bit)
 
void SetInfoBit (unsigned char bit)
 
bool IsInfoBit (unsigned char bit) const
 
void SetZero ()
 
void SetOne ()
 
void Set05 ()
 
void SetNan ()
 
void SetZeroNan ()
 
void Swap (Big< exp, man > &ss2)
 
void SetPi ()
 
void Set05Pi ()
 
void Set2Pi ()
 
void SetE ()
 
void SetLn2 ()
 
void SetLn10 ()
 
void SetMax ()
 
void SetMin ()
 
bool IsZero () const
 
bool IsSign () const
 
bool IsNan () const
 
void Abs ()
 
void Sgn ()
 
void SetSign ()
 
void ChangeSign ()
 
uint Add (Big< exp, man > ss2, bool round=true, bool adding=true)
 
uint Sub (const Big< exp, man > &ss2, bool round=true)
 
uint BitAnd (Big< exp, man > ss2)
 
uint BitOr (Big< exp, man > ss2)
 
uint BitXor (Big< exp, man > ss2)
 
uint MulUInt (uint ss2)
 
uint MulInt (sint ss2)
 
uint Mul (const Big< exp, man > &ss2, bool round=true)
 
uint Div (const Big< exp, man > &ss2, bool round=true)
 
uint Mod (const Big< exp, man > &ss2)
 
uint Mod2 () const
 
template<uint pow_size>
uint Pow (UInt< pow_size > pow)
 
template<uint pow_size>
uint Pow (Int< pow_size > pow)
 
uint PowUInt (Big< exp, man > pow)
 
uint PowInt (const Big< exp, man > &pow)
 
uint PowFrac (const Big< exp, man > &pow)
 
uint Pow (const Big< exp, man > &pow)
 
uint Sqrt ()
 
uint Exp (const Big< exp, man > &x)
 
uint Ln (const Big< exp, man > &x)
 
uint Log (const Big< exp, man > &x, const Big< exp, man > &base)
 
template<uint another_exp, uint another_man>
uint FromBig (const Big< another_exp, another_man > &another)
 
uint ToUInt () const
 
uint ToUInt (uint &result) const
 
sint ToInt () const
 
uint ToInt (uint &result) const
 
uint ToInt (sint &result) const
 
template<uint int_size>
uint ToUInt (UInt< int_size > &result) const
 
template<uint int_size>
uint ToInt (UInt< int_size > &result) const
 
template<uint int_size>
uint ToInt (Int< int_size > &result) const
 
uint FromUInt (uint value)
 
uint FromInt (uint value)
 
uint FromInt (sint value)
 
uint FromDouble (double value)
 
uint FromFloat (float value)
 
double ToDouble () const
 
float ToFloat () const
 
uint ToFloat (float &result) const
 
uint ToDouble (double &result) const
 
Big< exp, man > & operator= (sint value)
 
Big< exp, man > & operator= (uint value)
 
Big< exp, man > & operator= (float value)
 
Big< exp, man > & operator= (double value)
 
 Big (sint value)
 
 Big (uint value)
 
 Big (double value)
 
 Big (float value)
 
uint ToUInt (unsigned int &result) const
 
uint ToInt (unsigned int &result) const
 
uint ToInt (signed int &result) const
 
uint FromUInt (unsigned int value)
 
uint FromInt (unsigned int value)
 
uint FromInt (signed int value)
 
Big< exp, man > & operator= (unsigned int value)
 
 Big (unsigned int value)
 
Big< exp, man > & operator= (signed int value)
 
 Big (signed int value)
 
template<uint int_size>
uint FromUInt (UInt< int_size > value)
 
template<uint int_size>
uint FromInt (const UInt< int_size > &value)
 
template<uint int_size>
uint FromInt (Int< int_size > value)
 
template<uint int_size>
Big< exp, man > & operator= (const Int< int_size > &value)
 
template<uint int_size>
 Big (const Int< int_size > &value)
 
template<uint int_size>
Big< exp, man > & operator= (const UInt< int_size > &value)
 
template<uint int_size>
 Big (const UInt< int_size > &value)
 
template<uint another_exp, uint another_man>
Big< exp, man > & operator= (const Big< another_exp, another_man > &value)
 
template<uint another_exp, uint another_man>
 Big (const Big< another_exp, another_man > &value)
 
 Big ()
 
 ~Big ()
 
Big< exp, man > & operator= (const Big< exp, man > &value)
 
 Big (const Big< exp, man > &value)
 
uint ToString (std::string &result, uint base=10, bool scient=false, sint scient_from=15, sint round=-1, bool trim_zeroes=true, char comma='.') const
 
uint ToString (std::string &result, const Conv &conv) const
 
std::string ToString (const Conv &conv) const
 
std::string ToString (uint base=10) const
 
uint ToString (std::wstring &result, uint base=10, bool scient=false, sint scient_from=15, sint round=-1, bool trim_zeroes=true, wchar_t comma='.') const
 
uint ToString (std::wstring &result, const Conv &conv) const
 
std::wstring ToWString (const Conv &conv) const
 
std::wstring ToWString (uint base=10) const
 
uint FromString (const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
 
uint FromString (const char *source, const Conv &conv, const char **after_source=0, bool *value_read=0)
 
uint FromString (const std::string &string, uint base=10, const char **after_source=0, bool *value_read=0)
 
uint FromString (const std::string &string, const Conv &conv, const char **after_source=0, bool *value_read=0)
 
uint FromString (const wchar_t *source, uint base=10, const wchar_t **after_source=0, bool *value_read=0)
 
uint FromString (const wchar_t *source, const Conv &conv, const wchar_t **after_source=0, bool *value_read=0)
 
uint FromString (const std::wstring &string, uint base=10, const wchar_t **after_source=0, bool *value_read=0)
 
uint FromString (const std::wstring &string, const Conv &conv, const wchar_t **after_source=0, bool *value_read=0)
 
 Big (const char *string)
 
 Big (const std::string &string)
 
Big< exp, man > & operator= (const char *string)
 
Big< exp, man > & operator= (const std::string &string)
 
 Big (const wchar_t *string)
 
 Big (const std::wstring &string)
 
Big< exp, man > & operator= (const wchar_t *string)
 
Big< exp, man > & operator= (const std::wstring &string)
 
bool SmallerWithoutSignThan (const Big< exp, man > &ss2) const
 
bool GreaterWithoutSignThan (const Big< exp, man > &ss2) const
 
bool EqualWithoutSign (const Big< exp, man > &ss2) const
 
bool operator< (const Big< exp, man > &ss2) const
 
bool operator== (const Big< exp, man > &ss2) const
 
bool operator> (const Big< exp, man > &ss2) const
 
bool operator>= (const Big< exp, man > &ss2) const
 
bool operator<= (const Big< exp, man > &ss2) const
 
bool operator!= (const Big< exp, man > &ss2) const
 
Big< exp, man > operator- () const
 
Big< exp, man > operator- (const Big< exp, man > &ss2) const
 
Big< exp, man > & operator-= (const Big< exp, man > &ss2)
 
Big< exp, man > operator+ (const Big< exp, man > &ss2) const
 
Big< exp, man > & operator+= (const Big< exp, man > &ss2)
 
Big< exp, man > operator* (const Big< exp, man > &ss2) const
 
Big< exp, man > & operator*= (const Big< exp, man > &ss2)
 
Big< exp, man > operator/ (const Big< exp, man > &ss2) const
 
Big< exp, man > & operator/= (const Big< exp, man > &ss2)
 
Big< exp, man > & operator++ ()
 
Big< exp, man > operator++ (int)
 
Big< exp, man > & operator-- ()
 
Big< exp, man > operator-- (int)
 
Big< exp, man > operator & (const Big< exp, man > &p2) const
 
Big< exp, man > & operator &= (const Big< exp, man > &p2)
 
Big< exp, man > operator| (const Big< exp, man > &p2) const
 
Big< exp, man > & operator|= (const Big< exp, man > &p2)
 
Big< exp, man > operator^ (const Big< exp, man > &p2) const
 
Big< exp, man > & operator^= (const Big< exp, man > &p2)
 
void SkipFraction ()
 
void RemainFraction ()
 
bool IsInteger () const
 
uint Round ()
 

Static Public Member Functions

static const char * LibTypeStr ()
 
static LibTypeCode LibType ()
 

Data Fields

Int< exp > exponent
 
UInt< man > mantissa
 
unsigned char info
 

Friends

class Big< exp-1, man >
 
std::ostream & operator<< (std::ostream &s, const Big< exp, man > &l)
 
std::wostream & operator<< (std::wostream &s, const Big< exp, man > &l)
 
std::istream & operator>> (std::istream &s, Big< exp, man > &l)
 
std::wistream & operator>> (std::wistream &s, Big< exp, man > &l)
 

Detailed Description

template<uint exp, uint man>
class ttmath::Big< exp, man >

Big implements the floating point numbers.

Definition at line 63 of file ttmathbig.h.

Constructor & Destructor Documentation

§ Big() [1/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( sint  value)

a constructor for converting 'sint' to this class

Definition at line 3145 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromInt().

3146  {
3147  FromInt(value);
3148  }
uint FromInt(uint value)
Definition: ttmathbig.h:2546

§ Big() [2/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( uint  value)

a constructor for converting 'uint' to this class

Definition at line 3153 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromUInt().

3154  {
3155  FromUInt(value);
3156  }
uint FromUInt(uint value)
Definition: ttmathbig.h:2520

§ Big() [3/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( double  value)

a constructor for converting 'double' to this class

Definition at line 3162 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromDouble().

3163  {
3164  FromDouble(value);
3165  }
uint FromDouble(double value)
Definition: ttmathbig.h:2718

§ Big() [4/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( float  value)

§ Big() [5/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( unsigned int  value)

a constructor for converting 32 bit unsigned int to this class this constructor is created only on a 64bit platform***

Definition at line 3452 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromUInt().

3453  {
3454  FromUInt(value);
3455  }
uint FromUInt(uint value)
Definition: ttmathbig.h:2520

§ Big() [6/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( signed int  value)

a constructor for converting 32 bit signed int to this class this constructor is created only on a 64bit platform***

Definition at line 3474 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromInt(), ttmath::UInt< value_size >::table, and TTMATH_BITS_PER_UINT.

3475  {
3476  FromInt(value);
3477  }
uint FromInt(uint value)
Definition: ttmathbig.h:2546

§ Big() [7/15]

template<uint exp, uint man>
template<uint int_size>
ttmath::Big< exp, man >::Big ( const Int< int_size > &  value)

a constructor for converting from 'Int<int_size>' to this class

Definition at line 3580 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromInt().

3581  {
3582  FromInt(value);
3583  }
uint FromInt(uint value)
Definition: ttmathbig.h:2546

§ Big() [8/15]

template<uint exp, uint man>
template<uint int_size>
ttmath::Big< exp, man >::Big ( const UInt< int_size > &  value)

a constructor for converting from 'UInt<int_size>' to this class

Definition at line 3602 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromUInt().

3603  {
3604  FromUInt(value);
3605  }
uint FromUInt(uint value)
Definition: ttmathbig.h:2520

§ Big() [9/15]

template<uint exp, uint man>
template<uint another_exp, uint another_man>
ttmath::Big< exp, man >::Big ( const Big< another_exp, another_man > &  value)

a constructor for converting from 'Big<another_exp, another_man>' to this class

Definition at line 3624 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromBig().

3625  {
3626  FromBig(value);
3627  }
uint FromBig(const Big< another_exp, another_man > &another)
Definition: ttmathbig.h:2222

§ Big() [10/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( )

a default constructor

by default we don't set any of the members to zero only NaN flag is set

if you want the mantissa and exponent to be set to zero define TTMATH_BIG_DEFAULT_CLEAR macro (useful for debug purposes)

Definition at line 3640 of file ttmathbig.h.

References ttmath::Big< exp, man >::SetZeroNan(), and TTMATH_BIG_NAN.

Referenced by ttmath::Big< exp, man >::Big().

3641  {
3642  #ifdef TTMATH_BIG_DEFAULT_CLEAR
3643 
3644  SetZeroNan();
3645 
3646  #else
3647 
3648  info = TTMATH_BIG_NAN;
3649  // we're directly setting 'info' (instead of calling SetNan())
3650  // in order to get rid of a warning saying that 'info' is uninitialized
3651 
3652  #endif
3653  }
void SetZeroNan()
Definition: ttmathbig.h:306
#define TTMATH_BIG_NAN
Definition: ttmathbig.h:104

§ ~Big()

template<uint exp, uint man>
ttmath::Big< exp, man >::~Big ( )

a destructor

Definition at line 3659 of file ttmathbig.h.

3660  {
3661  }

§ Big() [11/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( const Big< exp, man > &  value)

a constructor for copying from another object of this class

Definition at line 3681 of file ttmathbig.h.

References ttmath::Big< exp, man >::operator=().

3682  {
3683  operator=(value);
3684  }
Big< exp, man > & operator=(sint value)
Definition: ttmathbig.h:3101

§ Big() [12/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( const char *  string)

a constructor for converting a string into this class

Definition at line 5303 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

5304  {
5305  FromString( string );
5306  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ Big() [13/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( const std::string &  string)

a constructor for converting a string into this class

Definition at line 5312 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

5313  {
5314  FromString( string.c_str() );
5315  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ Big() [14/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( const wchar_t *  string)

a constructor for converting a string into this class

Definition at line 5346 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

5347  {
5348  FromString( string );
5349  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ Big() [15/15]

template<uint exp, uint man>
ttmath::Big< exp, man >::Big ( const std::wstring &  string)

a constructor for converting a string into this class

Definition at line 5355 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

5356  {
5357  FromString( string.c_str() );
5358  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

Member Function Documentation

§ Abs()

template<uint exp, uint man>
void ttmath::Big< exp, man >::Abs ( )

this method clears the sign (there'll be an absolute value)

samples

  • -1 -> 1
  • 2 -> 2

Definition at line 682 of file ttmathbig.h.

References ttmath::Big< exp, man >::ClearInfoBit(), and TTMATH_BIG_SIGN.

Referenced by ttmath::Big< exp, man >::Exp(), ttmath::Big< exp, man >::Mul(), ttmath::Big< exp, man >::MulInt(), and ttmath::Big< exp, man >::PowUInt().

683  {
685  }
void ClearInfoBit(unsigned char bit)
Definition: ttmathbig.h:224
#define TTMATH_BIG_SIGN
Definition: ttmathbig.h:97

§ Add()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Add ( Big< exp, man >  ss2,
bool  round = true,
bool  adding = true 
)

Addition this = this + ss2

it returns carry if the sum is too big

Definition at line 930 of file ttmathbig.h.

References ttmath::Int< value_size >::Abs(), ttmath::Big< exp, man >::ChangeSign(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::SmallerWithoutSignThan(), ttmath::Big< exp, man >::Standardizing(), ttmath::Int< value_size >::Sub(), and ttmath::Big< exp, man >::Swap().

Referenced by ttmath::Big< exp, man >::Exp(), ttmath::Big< exp, man >::FromString(), ttmath::Big< exp, man >::Ln(), ttmath::Big< exp, man >::operator-(), ttmath::Big< exp, man >::Round(), ttmath::Big< exp, man >::Sqrt(), and ttmath::Big< exp, man >::Sub().

931  {
932  bool last_bit_set, rest_zero, do_adding, do_rounding, rounding_up;
933  Int<exp> exp_offset( exponent );
934  uint c = 0;
935 
936  if( IsNan() || ss2.IsNan() )
937  return CheckCarry(1);
938 
939  if( !adding )
940  ss2.ChangeSign(); // subtracting
941 
942  exp_offset.Sub( ss2.exponent );
943  exp_offset.Abs();
944 
945  // (1) abs(this) will be >= abs(ss2)
946  if( SmallerWithoutSignThan(ss2) )
947  Swap(ss2);
948 
949  if( ss2.IsZero() )
950  return 0;
951 
952  last_bit_set = rest_zero = do_adding = do_rounding = false;
953  rounding_up = (IsSign() == ss2.IsSign());
954 
955  AddCheckExponents(ss2, exp_offset, last_bit_set, rest_zero, do_adding, do_rounding);
956 
957  if( do_adding )
958  c += AddMantissas(ss2, last_bit_set, rest_zero);
959 
960  if( !round || !last_bit_set )
961  do_rounding = false;
962 
963  if( do_rounding )
964  c += RoundHalfToEven(rest_zero, rounding_up);
965 
966  if( do_adding || do_rounding )
967  c += Standardizing();
968 
969  return CheckCarry(c);
970  }
bool IsSign() const
Definition: ttmathbig.h:658
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
bool IsNan() const
Definition: ttmathbig.h:667
bool SmallerWithoutSignThan(const Big< exp, man > &ss2) const
Definition: ttmathbig.h:5401
unsigned long uint
Definition: ttmathtypes.h:238
uint Standardizing()
Definition: ttmathbig.h:173
void Swap(Big< exp, man > &ss2)
Definition: ttmathbig.h:316

§ BitAnd()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::BitAnd ( Big< exp, man >  ss2)

bitwise AND

this and ss2 must be >= 0

return values:

  • 0 - ok
  • 1 - carry
  • 2 - this or ss2 was negative

Definition at line 994 of file ttmathbig.h.

References ttmath::Int< value_size >::Abs(), ttmath::UInt< value_size >::BitAnd(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::Rcr(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetZero(), ttmath::Big< exp, man >::SmallerWithoutSignThan(), ttmath::Big< exp, man >::Standardizing(), ttmath::Int< value_size >::Sub(), ttmath::Big< exp, man >::Swap(), ttmath::Int< value_size >::ToInt(), and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::operator &().

995  {
996  if( IsNan() || ss2.IsNan() )
997  return CheckCarry(1);
998 
999  if( IsSign() || ss2.IsSign() )
1000  {
1001  SetNan();
1002  return 2;
1003  }
1004 
1005  if( IsZero() )
1006  return 0;
1007 
1008  if( ss2.IsZero() )
1009  {
1010  SetZero();
1011  return 0;
1012  }
1013 
1014  Int<exp> exp_offset( exponent );
1015  Int<exp> mantissa_size_in_bits( man * TTMATH_BITS_PER_UINT );
1016 
1017  uint c = 0;
1018 
1019  exp_offset.Sub( ss2.exponent );
1020  exp_offset.Abs();
1021 
1022  // abs(this) will be >= abs(ss2)
1023  if( SmallerWithoutSignThan(ss2) )
1024  Swap(ss2);
1025 
1026  if( exp_offset >= mantissa_size_in_bits )
1027  {
1028  // the second value is too small
1029  SetZero();
1030  return 0;
1031  }
1032 
1033  // exp_offset < mantissa_size_in_bits, moving 'exp_offset' times
1034  ss2.mantissa.Rcr( exp_offset.ToInt(), 0 );
1035  mantissa.BitAnd(ss2.mantissa);
1036 
1037  c += Standardizing();
1038 
1039  return CheckCarry(c);
1040  }
bool IsSign() const
Definition: ttmathbig.h:658
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
bool IsZero() const
Definition: ttmathbig.h:648
void BitAnd(const UInt< value_size > &ss2)
Definition: ttmathuint.h:743
bool IsNan() const
Definition: ttmathbig.h:667
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
bool SmallerWithoutSignThan(const Big< exp, man > &ss2) const
Definition: ttmathbig.h:5401
unsigned long uint
Definition: ttmathtypes.h:238
uint Standardizing()
Definition: ttmathbig.h:173
void SetZero()
Definition: ttmathbig.h:256
void Swap(Big< exp, man > &ss2)
Definition: ttmathbig.h:316

§ BitOr()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::BitOr ( Big< exp, man >  ss2)

bitwise OR

this and ss2 must be >= 0 return values:

  • 0 - ok
  • 1 - carry
  • 2 - this or ss2 was negative

Definition at line 1053 of file ttmathbig.h.

References ttmath::Int< value_size >::Abs(), ttmath::UInt< value_size >::BitOr(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::Rcr(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SmallerWithoutSignThan(), ttmath::Big< exp, man >::Standardizing(), ttmath::Int< value_size >::Sub(), ttmath::Big< exp, man >::Swap(), ttmath::Int< value_size >::ToInt(), and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::operator &().

1054  {
1055  if( IsNan() || ss2.IsNan() )
1056  return CheckCarry(1);
1057 
1058  if( IsSign() || ss2.IsSign() )
1059  {
1060  SetNan();
1061  return 2;
1062  }
1063 
1064  if( IsZero() )
1065  {
1066  *this = ss2;
1067  return 0;
1068  }
1069 
1070  if( ss2.IsZero() )
1071  return 0;
1072 
1073  Int<exp> exp_offset( exponent );
1074  Int<exp> mantissa_size_in_bits( man * TTMATH_BITS_PER_UINT );
1075 
1076  uint c = 0;
1077 
1078  exp_offset.Sub( ss2.exponent );
1079  exp_offset.Abs();
1080 
1081  // abs(this) will be >= abs(ss2)
1082  if( SmallerWithoutSignThan(ss2) )
1083  Swap(ss2);
1084 
1085  if( exp_offset >= mantissa_size_in_bits )
1086  // the second value is too small
1087  return 0;
1088 
1089  // exp_offset < mantissa_size_in_bits, moving 'exp_offset' times
1090  ss2.mantissa.Rcr( exp_offset.ToInt(), 0 );
1091  mantissa.BitOr(ss2.mantissa);
1092 
1093  c += Standardizing();
1094 
1095  return CheckCarry(c);
1096  }
bool IsSign() const
Definition: ttmathbig.h:658
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
bool IsZero() const
Definition: ttmathbig.h:648
void BitOr(const UInt< value_size > &ss2)
Definition: ttmathuint.h:755
bool IsNan() const
Definition: ttmathbig.h:667
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
bool SmallerWithoutSignThan(const Big< exp, man > &ss2) const
Definition: ttmathbig.h:5401
unsigned long uint
Definition: ttmathtypes.h:238
uint Standardizing()
Definition: ttmathbig.h:173
void Swap(Big< exp, man > &ss2)
Definition: ttmathbig.h:316

§ BitXor()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::BitXor ( Big< exp, man >  ss2)

bitwise XOR

this and ss2 must be >= 0 return values:

  • 0 - ok
  • 1 - carry
  • 2 - this or ss2 was negative

Definition at line 1109 of file ttmathbig.h.

References ttmath::Int< value_size >::Abs(), ttmath::UInt< value_size >::BitXor(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::Rcr(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SmallerWithoutSignThan(), ttmath::Big< exp, man >::Standardizing(), ttmath::Int< value_size >::Sub(), ttmath::Big< exp, man >::Swap(), ttmath::Int< value_size >::ToInt(), and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::operator &().

1110  {
1111  if( IsNan() || ss2.IsNan() )
1112  return CheckCarry(1);
1113 
1114  if( IsSign() || ss2.IsSign() )
1115  {
1116  SetNan();
1117  return 2;
1118  }
1119 
1120  if( ss2.IsZero() )
1121  return 0;
1122 
1123  if( IsZero() )
1124  {
1125  *this = ss2;
1126  return 0;
1127  }
1128 
1129  Int<exp> exp_offset( exponent );
1130  Int<exp> mantissa_size_in_bits( man * TTMATH_BITS_PER_UINT );
1131 
1132  uint c = 0;
1133 
1134  exp_offset.Sub( ss2.exponent );
1135  exp_offset.Abs();
1136 
1137  // abs(this) will be >= abs(ss2)
1138  if( SmallerWithoutSignThan(ss2) )
1139  Swap(ss2);
1140 
1141  if( exp_offset >= mantissa_size_in_bits )
1142  // the second value is too small
1143  return 0;
1144 
1145  // exp_offset < mantissa_size_in_bits, moving 'exp_offset' times
1146  ss2.mantissa.Rcr( exp_offset.ToInt(), 0 );
1147  mantissa.BitXor(ss2.mantissa);
1148 
1149  c += Standardizing();
1150 
1151  return CheckCarry(c);
1152  }
bool IsSign() const
Definition: ttmathbig.h:658
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
void BitXor(const UInt< value_size > &ss2)
Definition: ttmathuint.h:767
bool SmallerWithoutSignThan(const Big< exp, man > &ss2) const
Definition: ttmathbig.h:5401
unsigned long uint
Definition: ttmathtypes.h:238
uint Standardizing()
Definition: ttmathbig.h:173
void Swap(Big< exp, man > &ss2)
Definition: ttmathbig.h:316

§ ChangeSign()

template<uint exp, uint man>
void ttmath::Big< exp, man >::ChangeSign ( )

this method changes the sign when there is a value of zero then the sign is not changed

samples

  • -1 -> 1
  • 2 -> -2

Definition at line 740 of file ttmathbig.h.

References ttmath::Int< value_size >::AddOne(), ttmath::UInt< value_size >::AddOne(), ttmath::Big< exp, man >::ClearInfoBit(), ttmath::Big< exp, man >::IsSign(), ttmath::UInt< value_size >::IsTheLowestBitSet(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::Rcr(), ttmath::Big< exp, man >::SetInfoBit(), ttmath::UInt< value_size >::SubOne(), and TTMATH_BIG_SIGN.

Referenced by ttmath::Big< exp, man >::Add(), ttmath::Big< exp, man >::FromString(), and ttmath::Big< exp, man >::operator-().

741  {
742  // we don't have to check the NaN flag here
743 
744  if( IsZero() )
745  return;
746 
747  if( IsSign() )
749  else
751  }
bool IsSign() const
Definition: ttmathbig.h:658
void ClearInfoBit(unsigned char bit)
Definition: ttmathbig.h:224
bool IsZero() const
Definition: ttmathbig.h:648
#define TTMATH_BIG_SIGN
Definition: ttmathbig.h:97
void SetInfoBit(unsigned char bit)
Definition: ttmathbig.h:236

§ CheckCarry()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::CheckCarry ( uint  c)

§ ClearInfoBit()

template<uint exp, uint man>
void ttmath::Big< exp, man >::ClearInfoBit ( unsigned char  bit)

this method clears a specific bit in the 'info' variable

bit is one of: TTMATH_BIG_SIGN, TTMATH_BIG_NAN etc.

Definition at line 224 of file ttmathbig.h.

Referenced by ttmath::Big< exp, man >::Abs(), ttmath::Big< exp, man >::ChangeSign(), and ttmath::Big< exp, man >::Standardizing().

225  {
226  info = info & (~bit);
227  }

§ Div()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Div ( const Big< exp, man > &  ss2,
bool  round = true 
)

division this = this / ss2

return value:

  • 0 - ok
  • 1 - carry (in a division carry can be as well)
  • 2 - improper argument (ss2 is zero)

Definition at line 1452 of file ttmathbig.h.

References ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::Mul(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SkipFraction(), ttmath::Big< exp, man >::SmallerWithoutSignThan(), ttmath::Big< exp, man >::Sub(), and TTMATH_REFERENCE_ASSERT.

Referenced by ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::Exp(), ttmath::Big< exp, man >::FromString(), ttmath::Big< exp, man >::Log(), ttmath::Big< exp, man >::operator-(), ttmath::Big< exp, man >::Pow(), ttmath::Big< exp, man >::PowInt(), and ttmath::Big< exp, man >::Sqrt().

1453  {
1454  if( this == &ss2 )
1455  {
1456  Big<exp, man> copy_ss2(ss2);
1457  return DivRef(copy_ss2, round);
1458  }
1459  else
1460  {
1461  return DivRef(ss2, round);
1462  }
1463  }

§ EqualWithoutSign()

template<uint exp, uint man>
bool ttmath::Big< exp, man >::EqualWithoutSign ( const Big< exp, man > &  ss2) const

this method performs the formula 'abs(this) == abs(ss2)' and returns the result

(in other words it treats 'this' and 'ss2' as values without a sign) we don't check the NaN flag

Definition at line 5473 of file ttmathbig.h.

References ttmath::Big< exp, man >::GreaterWithoutSignThan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), and ttmath::Big< exp, man >::SmallerWithoutSignThan().

5474  {
5475  if( IsZero() )
5476  {
5477  if( ss2.IsZero() )
5478  {
5479  // we've got two zeroes
5480  return true;
5481  }
5482  else
5483  {
5484  // this==0 and ss2!=0
5485  return false;
5486  }
5487  }
5488 
5489  if( ss2.IsZero() )
5490  {
5491  // this!=0 and ss2==0
5492  return false;
5493  }
5494 
5495  if( exponent==ss2.exponent && mantissa==ss2.mantissa )
5496  return true;
5497 
5498  return false;
5499  }
bool IsZero() const
Definition: ttmathbig.h:648

§ Exp()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Exp ( const Big< exp, man > &  x)

Exponent this = exp(x) = e^x

we're using the fact that our value is stored in form of:

x = mantissa * 2^exponent

then

e^x = e^(mantissa* 2^exponent) or
e^x = (e^mantissa)^(2^exponent)

'Exp' returns a carry if we can't count the result ('x' is too big)

Definition at line 1948 of file ttmathbig.h.

References ttmath::Big< exp, man >::Abs(), ttmath::Int< value_size >::Add(), ttmath::Big< exp, man >::Add(), ttmath::Int< value_size >::AddOne(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::Mul(), ttmath::Big< exp, man >::PowUInt(), ttmath::Big< exp, man >::SetOne(), ttmath::UInt< value_size >::SetZero(), ttmath::Big< exp, man >::SetZero(), ttmath::Big< exp, man >::Sub(), ttmath::UInt< value_size >::table, TTMATH_ARITHMETIC_MAX_LOOP, TTMATH_BITS_PER_UINT, and TTMATH_UINT_HIGHEST_BIT.

Referenced by ttmath::Big< exp, man >::PowFrac(), and ttmath::Big< exp, man >::Sqrt().

1949  {
1950  uint c = 0;
1951 
1952  if( x.IsNan() )
1953  return CheckCarry(1);
1954 
1955  if( x.IsZero() )
1956  {
1957  SetOne();
1958  return 0;
1959  }
1960 
1961  // m will be the value of the mantissa in range (-1,1)
1962  Big<exp,man> m(x);
1963  m.exponent = -sint(man*TTMATH_BITS_PER_UINT);
1964 
1965  // 'e_' will be the value of '2^exponent'
1966  // e_.mantissa.table[man-1] = TTMATH_UINT_HIGHEST_BIT; and
1967  // e_.exponent.Add(1) mean:
1968  // e_.mantissa.table[0] = 1;
1969  // e_.Standardizing();
1970  // e_.exponent.Add(man*TTMATH_BITS_PER_UINT)
1971  // (we must add 'man*TTMATH_BITS_PER_UINT' because we've taken it from the mantissa)
1972  Big<exp,man> e_(x);
1973  e_.mantissa.SetZero();
1974  e_.mantissa.table[man-1] = TTMATH_UINT_HIGHEST_BIT;
1975  c += e_.exponent.Add(1);
1976  e_.Abs();
1977 
1978  /*
1979  now we've got:
1980  m - the value of the mantissa in range (-1,1)
1981  e_ - 2^exponent
1982 
1983  e_ can be as:
1984  ...2^-2, 2^-1, 2^0, 2^1, 2^2 ...
1985  ...1/4 , 1/2 , 1 , 2 , 4 ...
1986 
1987  above one e_ is integer
1988 
1989  if e_ is greater than 1 we calculate the exponent as:
1990  e^(m * e_) = ExpSurrounding0(m) ^ e_
1991  and if e_ is smaller or equal one we calculate the exponent in this way:
1992  e^(m * e_) = ExpSurrounding0(m* e_)
1993  because if e_ is smaller or equal 1 then the product of m*e_ is smaller or equal m
1994  */
1995 
1996  if( e_ <= 1 )
1997  {
1998  m.Mul(e_);
1999  ExpSurrounding0(m);
2000  }
2001  else
2002  {
2003  ExpSurrounding0(m);
2004  c += PowUInt(e_);
2005  }
2006 
2007  return CheckCarry(c);
2008  }
signed long sint
Definition: ttmathtypes.h:243
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetOne()
Definition: ttmathbig.h:271
#define TTMATH_UINT_HIGHEST_BIT
Definition: ttmathtypes.h:258
uint PowUInt(Big< exp, man > pow)
Definition: ttmathbig.h:1657
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
unsigned long uint
Definition: ttmathtypes.h:238

§ FromBig()

template<uint exp, uint man>
template<uint another_exp, uint another_man>
uint ttmath::Big< exp, man >::FromBig ( const Big< another_exp, another_man > &  another)

converting methods

converting from another type of a Big object

Definition at line 2222 of file ttmathbig.h.

References ttmath::Int< value_size >::AddInt(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Int< value_size >::FromInt(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::SetNan(), ttmath::Int< value_size >::SubInt(), ttmath::UInt< value_size >::table, ttmath::Int< value_size >::ToInt(), and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::Big(), and ttmath::Big< exp, man >::operator=().

2223  {
2224  info = another.info;
2225 
2226  if( IsNan() )
2227  return 1;
2228 
2229  if( exponent.FromInt(another.exponent) )
2230  {
2231  SetNan();
2232  return 1;
2233  }
2234 
2235  uint man_len_min = (man < another_man)? man : another_man;
2236  uint i;
2237  uint c = 0;
2238 
2239  for( i = 0 ; i<man_len_min ; ++i )
2240  mantissa.table[man-1-i] = another.mantissa.table[another_man-1-i];
2241 
2242  for( ; i<man ; ++i )
2243  mantissa.table[man-1-i] = 0;
2244 
2245 
2246  // MS Visual Express 2005 reports a warning (in the lines with 'uint man_diff = ...'):
2247  // warning C4307: '*' : integral constant overflow
2248  // but we're using 'if( man > another_man )' and 'if( man < another_man )' and there'll be no such situation here
2249  #ifdef _MSC_VER
2250  #pragma warning( disable: 4307 )
2251  #endif
2252 
2253  if( man > another_man )
2254  {
2255  uint man_diff = (man - another_man) * TTMATH_BITS_PER_UINT;
2256  c += exponent.SubInt(man_diff, 0);
2257  }
2258  else
2259  if( man < another_man )
2260  {
2261  uint man_diff = (another_man - man) * TTMATH_BITS_PER_UINT;
2262  c += exponent.AddInt(man_diff, 0);
2263  }
2264 
2265  #ifdef _MSC_VER
2266  #pragma warning( default: 4307 )
2267  #endif
2268 
2269  // mantissa doesn't have to be standardized (either the highest bit is set or all bits are equal zero)
2270  CorrectZero();
2271 
2272  return CheckCarry(c);
2273  }
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
uint table[value_size]
Definition: ttmathuint.h:81
uint FromInt(const Int< argument_size > &p)
Definition: ttmathint.h:697
void SetNan()
Definition: ttmathbig.h:296
bool IsNan() const
Definition: ttmathbig.h:667
uint AddInt(uint value, uint index=0)
Definition: ttmathint.h:237
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
unsigned long uint
Definition: ttmathtypes.h:238
uint SubInt(uint value, uint index=0)
Definition: ttmathint.h:314

§ FromDouble()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromDouble ( double  value)

this method converts from standard double into this class

standard double means IEEE-754 floating point value with 64 bits it is as follows (from http://www.psc.edu/general/software/packages/ieee/ieee.html):

The IEEE double precision floating point standard representation requires a 64 bit word, which may be represented as numbered from 0 to 63, left to right. The first bit is the sign bit, S, the next eleven bits are the exponent bits, 'E', and the final 52 bits are the fraction 'F':

S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
0 1        11 12                                                63

The value V represented by the word may be determined as follows:

  • If E=2047 and F is nonzero, then V=NaN ("Not a number")
  • If E=2047 and F is zero and S is 1, then V=-Infinity
  • If E=2047 and F is zero and S is 0, then V=Infinity
  • If 0<E<2047 then V=(-1)**S * 2 ** (E-1023) * (1.F) where "1.F" is intended to represent the binary number created by prefixing F with an implicit leading 1 and a binary point.
  • If E=0 and F is nonzero, then V=(-1)**S * 2 ** (-1022) * (0.F) These are "unnormalized" values.
  • If E=0 and F is zero and S is 1, then V=-0
  • If E=0 and F is zero and S is 0, then V=0

Definition at line 2718 of file ttmathbig.h.

References ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetZero(), ttmath::Big< exp, man >::Standardizing(), ttmath::UInt< value_size >::table, and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::Big(), ttmath::Big< exp, man >::FromFloat(), ttmath::Big< exp, man >::FromInt(), and ttmath::Big< exp, man >::operator=().

2719  {
2720  // I am not sure what will be on a plaltform which has
2721  // a different endianness... but we use this library only
2722  // on x86 and amd (intel) 64 bits (as there's a lot of assembler code)
2723  union
2724  {
2725  double d;
2726  uint u; // one 64bit word
2727  } temp;
2728 
2729  temp.d = value;
2730 
2731  sint e = (temp.u & 0x7FF0000000000000ul) >> 52;
2732  uint m = (temp.u & 0xFFFFFFFFFFFFFul) << 11;
2733 
2734  if( e == 2047 )
2735  {
2736  // If E=2047 and F is nonzero, then V=NaN ("Not a number")
2737  // If E=2047 and F is zero and S is 1, then V=-Infinity
2738  // If E=2047 and F is zero and S is 0, then V=Infinity
2739 
2740  // we do not support -Infinity and +Infinity
2741  // we assume that there is always NaN
2742 
2743  SetNan();
2744  }
2745  else
2746  if( e > 0 )
2747  {
2748  // If 0<E<2047 then
2749  // V=(-1)**S * 2 ** (E-1023) * (1.F)
2750  // where "1.F" is intended to represent the binary number
2751  // created by prefixing F with an implicit leading 1 and a binary point.
2752 
2753  FromDouble_SetExpAndMan((temp.u & 0x8000000000000000ul) != 0,
2754  e - 1023 - man*TTMATH_BITS_PER_UINT + 1,
2755  0x8000000000000000ul, m);
2756 
2757  // we do not have to call Standardizing() here
2758  // because the mantissa will have the highest bit set
2759  }
2760  else
2761  {
2762  // e == 0
2763 
2764  if( m != 0 )
2765  {
2766  // If E=0 and F is nonzero,
2767  // then V=(-1)**S * 2 ** (-1022) * (0.F)
2768  // These are "unnormalized" values.
2769 
2770  FromDouble_SetExpAndMan(bool(temp.u & 0x8000000000000000ul),
2771  e - 1022 - man*TTMATH_BITS_PER_UINT + 1, 0, m);
2772  Standardizing();
2773  }
2774  else
2775  {
2776  // If E=0 and F is zero and S is 1, then V=-0
2777  // If E=0 and F is zero and S is 0, then V=0
2778 
2779  // we do not support -0 or 0, only is one 0
2780  SetZero();
2781  }
2782  }
2783 
2784  return 0; // never be a carry
2785  }
signed long sint
Definition: ttmathtypes.h:243
void SetNan()
Definition: ttmathbig.h:296
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
unsigned long uint
Definition: ttmathtypes.h:238
uint Standardizing()
Definition: ttmathbig.h:173
void SetZero()
Definition: ttmathbig.h:256

§ FromFloat()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromFloat ( float  value)

this method converts from float to this class

Definition at line 2815 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromDouble().

Referenced by ttmath::Big< exp, man >::Big(), and ttmath::Big< exp, man >::operator=().

2816  {
2817  return FromDouble(double(value));
2818  }
uint FromDouble(double value)
Definition: ttmathbig.h:2718

§ FromInt() [1/4]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromInt ( uint  value)

a method for converting 'uint' to this class

Definition at line 2546 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromUInt().

Referenced by ttmath::Big< exp, man >::Big(), ttmath::Big< exp, man >::Ln(), ttmath::Big< exp, man >::operator=(), and ttmath::Big< exp, man >::ToInt().

2547  {
2548  return FromUInt(value);
2549  }
uint FromUInt(uint value)
Definition: ttmathbig.h:2520

§ FromInt() [2/4]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromInt ( sint  value)

a method for converting 'sint' to this class

Definition at line 2555 of file ttmathbig.h.

References ttmath::UInt< value_size >::CompensationToLeft(), ttmath::Big< exp, man >::FromDouble(), ttmath::Big< exp, man >::FromUInt(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetSign(), ttmath::Big< exp, man >::SetZero(), ttmath::UInt< value_size >::table, and TTMATH_BITS_PER_UINT.

2556  {
2557  bool is_sign = false;
2558 
2559  if( value < 0 )
2560  {
2561  value = -value;
2562  is_sign = true;
2563  }
2564 
2565  FromUInt(uint(value));
2566 
2567  if( is_sign )
2568  SetSign();
2569 
2570  return 0;
2571  }
void SetSign()
Definition: ttmathbig.h:726
uint FromUInt(uint value)
Definition: ttmathbig.h:2520
unsigned long uint
Definition: ttmathtypes.h:238

§ FromInt() [3/4]

template<uint exp, uint man>
template<uint int_size>
uint ttmath::Big< exp, man >::FromInt ( const UInt< int_size > &  value)

a method for converting from 'UInt<int_size>' to this class

Definition at line 3533 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromUInt().

3534  {
3535  return FromUInt(value);
3536  }
uint FromUInt(uint value)
Definition: ttmathbig.h:2520

§ FromInt() [4/4]

template<uint exp, uint man>
template<uint int_size>
uint ttmath::Big< exp, man >::FromInt ( Int< int_size >  value)

a method for converting from 'Int<int_size>' to this class

Definition at line 3543 of file ttmathbig.h.

References ttmath::Int< value_size >::ChangeSign(), ttmath::UInt< value_size >::CompensationToLeft(), ttmath::Int< value_size >::IsSign(), and ttmath::Big< exp, man >::SetSign().

3544  {
3545  info = 0;
3546  bool is_sign = false;
3547 
3548  if( value.IsSign() )
3549  {
3550  value.ChangeSign();
3551  is_sign = true;
3552  }
3553 
3554  sint compensation = (sint)value.CompensationToLeft();
3555  FromUIntOrInt(value, compensation);
3556 
3557  if( is_sign )
3558  SetSign();
3559 
3560  return 0;
3561  }
signed long sint
Definition: ttmathtypes.h:243
void SetSign()
Definition: ttmathbig.h:726

§ FromString() [1/8]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromString ( const char *  source,
uint  base = 10,
const char **  after_source = 0,
bool *  value_read = 0 
)

a method for converting a string into its value

it returns 1 if the value is too big – we cannot pass it into the range of our class Big<exp,man> (or if the base is incorrect)

that means only digits before the comma operator can make this value too big, all digits after the comma we can ignore

'source' - pointer to the string for parsing

if 'after_source' is set that when this method finishes it sets the pointer to the new first character after parsed value

'value_read' - if the pointer is provided that means the value_read will be true only when a value has been actually read, there can be situation where only such a string '-' or '+' will be parsed – 'after_source' will be different from 'source' but no value has been read (there are no digits) on other words if 'value_read' is true – there is at least one digit in the string

Definition at line 4931 of file ttmathbig.h.

References ttmath::Conv::base.

Referenced by ttmath::Big< exp, man >::Big(), ttmath::Big< exp, man >::FromString(), and ttmath::Big< exp, man >::operator=().

4932  {
4933  Conv conv;
4934  conv.base = base;
4935 
4936  return FromStringBase(source, conv, after_source, value_read);
4937  }

§ FromString() [2/8]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromString ( const char *  source,
const Conv conv,
const char **  after_source = 0,
bool *  value_read = 0 
)

a method for converting a string into its value

Definition at line 4943 of file ttmathbig.h.

4944  {
4945  return FromStringBase(source, conv, after_source, value_read);
4946  }

§ FromString() [3/8]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromString ( const std::string &  string,
uint  base = 10,
const char **  after_source = 0,
bool *  value_read = 0 
)

a method for converting a string into its value

Definition at line 4952 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

4953  {
4954  return FromString(string.c_str(), base, after_source, value_read);
4955  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ FromString() [4/8]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromString ( const std::string &  string,
const Conv conv,
const char **  after_source = 0,
bool *  value_read = 0 
)

a method for converting a string into its value

Definition at line 4961 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

4962  {
4963  return FromString(string.c_str(), conv, after_source, value_read);
4964  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ FromString() [5/8]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromString ( const wchar_t *  source,
uint  base = 10,
const wchar_t **  after_source = 0,
bool *  value_read = 0 
)

a method for converting a string into its value

Definition at line 4972 of file ttmathbig.h.

References ttmath::Conv::base.

4973  {
4974  Conv conv;
4975  conv.base = base;
4976 
4977  return FromStringBase(source, conv, after_source, value_read);
4978  }

§ FromString() [6/8]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromString ( const wchar_t *  source,
const Conv conv,
const wchar_t **  after_source = 0,
bool *  value_read = 0 
)

a method for converting a string into its value

Definition at line 4984 of file ttmathbig.h.

4985  {
4986  return FromStringBase(source, conv, after_source, value_read);
4987  }

§ FromString() [7/8]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromString ( const std::wstring &  string,
uint  base = 10,
const wchar_t **  after_source = 0,
bool *  value_read = 0 
)

a method for converting a string into its value

Definition at line 4993 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

4994  {
4995  return FromString(string.c_str(), base, after_source, value_read);
4996  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ FromString() [8/8]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromString ( const std::wstring &  string,
const Conv conv,
const wchar_t **  after_source = 0,
bool *  value_read = 0 
)

§ FromUInt() [1/2]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::FromUInt ( uint  value)

a method for converting 'uint' to this class

Definition at line 2520 of file ttmathbig.h.

References ttmath::Big< exp, man >::SetZero(), ttmath::Big< exp, man >::Standardizing(), ttmath::UInt< value_size >::table, and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::Big(), ttmath::Big< exp, man >::FromInt(), ttmath::Big< exp, man >::operator=(), and ttmath::Big< exp, man >::ToInt().

2521  {
2522  if( value == 0 )
2523  {
2524  SetZero();
2525  return 0;
2526  }
2527 
2528  info = 0;
2529 
2530  for(uint i=0 ; i<man-1 ; ++i)
2531  mantissa.table[i] = 0;
2532 
2533  mantissa.table[man-1] = value;
2534  exponent = -sint(man-1) * sint(TTMATH_BITS_PER_UINT);
2535 
2536  // there shouldn't be a carry because 'value' has the 'uint' type
2537  Standardizing();
2538 
2539  return 0;
2540  }
signed long sint
Definition: ttmathtypes.h:243
uint table[value_size]
Definition: ttmathuint.h:81
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
unsigned long uint
Definition: ttmathtypes.h:238
uint Standardizing()
Definition: ttmathbig.h:173
void SetZero()
Definition: ttmathbig.h:256

§ FromUInt() [2/2]

template<uint exp, uint man>
template<uint int_size>
uint ttmath::Big< exp, man >::FromUInt ( UInt< int_size >  value)

a method for converting from 'UInt<int_size>' to this class

Definition at line 3520 of file ttmathbig.h.

References ttmath::UInt< value_size >::CompensationToLeft().

3521  {
3522  info = 0;
3523  sint compensation = (sint)value.CompensationToLeft();
3524 
3525  return FromUIntOrInt(value, compensation);
3526  }
signed long sint
Definition: ttmathtypes.h:243

§ GreaterWithoutSignThan()

template<uint exp, uint man>
bool ttmath::Big< exp, man >::GreaterWithoutSignThan ( const Big< exp, man > &  ss2) const

this method performs the formula 'abs(this) > abs(ss2)' and returns the result

(in other words it treats 'this' and 'ss2' as values without a sign) we don't check the NaN flag

Definition at line 5435 of file ttmathbig.h.

References ttmath::Big< exp, man >::IsZero().

Referenced by ttmath::Big< exp, man >::EqualWithoutSign().

5436  {
5437  if( IsZero() )
5438  {
5439  if( ss2.IsZero() )
5440  {
5441  // we've got two zeroes
5442  return false;
5443  }
5444  else
5445  {
5446  // this==0 and ss2!=0
5447  return false;
5448  }
5449  }
5450 
5451  if( ss2.IsZero() )
5452  {
5453  // this!=0 and ss2==0
5454  return true;
5455  }
5456 
5457  // we're using the fact that all bits in mantissa are pushed
5458  // into the left side -- Standardizing()
5459  if( exponent == ss2.exponent )
5460  return mantissa > ss2.mantissa;
5461 
5462  return exponent > ss2.exponent;
5463  }
bool IsZero() const
Definition: ttmathbig.h:648

§ IsInfoBit()

template<uint exp, uint man>
bool ttmath::Big< exp, man >::IsInfoBit ( unsigned char  bit) const

this method returns true if a specific bit in the 'info' variable is set

bit is one of: TTMATH_BIG_SIGN, TTMATH_BIG_NAN etc.

Definition at line 247 of file ttmathbig.h.

Referenced by ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), and ttmath::Big< exp, man >::IsZero().

248  {
249  return (info & bit) != 0;
250  }

§ IsInteger()

template<uint exp, uint man>
bool ttmath::Big< exp, man >::IsInteger ( ) const

this method returns true if the value is integer (there is no a fraction)

(we don't check NaN)

Definition at line 5865 of file ttmathbig.h.

References ttmath::Int< value_size >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::table, ttmath::Int< value_size >::ToInt(), TTMATH_BITS_PER_UINT, and TTMATH_UINT_MAX_VALUE.

Referenced by ttmath::Big< exp, man >::Pow(), and ttmath::Big< exp, man >::Sqrt().

5866  {
5867  if( IsZero() )
5868  return true;
5869 
5870  if( !exponent.IsSign() )
5871  // exponent >=0 -- the value don't have any fractions
5872  return true;
5873 
5874  if( exponent <= -sint(man*TTMATH_BITS_PER_UINT) )
5875  // the value is from (-1,1)
5876  return false;
5877 
5878  // exponent is in range (-man*TTMATH_BITS_PER_UINT, 0)
5879  sint e = exponent.ToInt();
5880  e = -e; // e means how many bits we must check
5881 
5882  uint len = e / TTMATH_BITS_PER_UINT;
5883  uint rest = e % TTMATH_BITS_PER_UINT;
5884  uint i = 0;
5885 
5886  for( ; i<len ; ++i )
5887  if( mantissa.table[i] != 0 )
5888  return false;
5889 
5890  if( rest > 0 )
5891  {
5892  uint rest_mask = TTMATH_UINT_MAX_VALUE >> (TTMATH_BITS_PER_UINT - rest);
5893  if( (mantissa.table[i] & rest_mask) != 0 )
5894  return false;
5895  }
5896 
5897  return true;
5898  }
signed long sint
Definition: ttmathtypes.h:243
uint table[value_size]
Definition: ttmathuint.h:81
bool IsZero() const
Definition: ttmathbig.h:648
#define TTMATH_UINT_MAX_VALUE
Definition: ttmathtypes.h:264
bool IsSign() const
Definition: ttmathint.h:156
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
unsigned long uint
Definition: ttmathtypes.h:238
sint ToInt() const
Definition: ttmathint.h:1132

§ IsNan()

template<uint exp, uint man>
bool ttmath::Big< exp, man >::IsNan ( ) const

§ IsSign()

template<uint exp, uint man>
bool ttmath::Big< exp, man >::IsSign ( ) const

§ IsZero()

template<uint exp, uint man>
bool ttmath::Big< exp, man >::IsZero ( ) const

§ LibType()

template<uint exp, uint man>
static LibTypeCode ttmath::Big< exp, man >::LibType ( )
static

returning the currect type of the library

Definition at line 154 of file ttmathbig.h.

References ttmath::UInt< value_size >::LibType().

155  {
156  return UInt<man>::LibType();
157  }
static LibTypeCode LibType()

§ LibTypeStr()

template<uint exp, uint man>
static const char* ttmath::Big< exp, man >::LibTypeStr ( )
static

returning the string represents the currect type of the library we have following types:

  • 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 145 of file ttmathbig.h.

References ttmath::UInt< value_size >::LibTypeStr().

146  {
147  return UInt<man>::LibTypeStr();
148  }
static const char * LibTypeStr()

§ Ln()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Ln ( const Big< exp, man > &  x)

Natural logarithm this = ln(x) (a logarithm with the base equal 'e')

we're using the fact that our value is stored in form of:

x = mantissa * 2^exponent

then

ln(x) = ln (mantissa * 2^exponent) = ln (mantissa) + (exponent * ln (2))

the mantissa we'll show as a value from range <1,2) because the logarithm is decreasing too fast when 'x' is going to 0

return values:

  • 0 - ok
  • 1 - overflow (carry)
  • 2 - incorrect argument (x<=0)

Definition at line 2126 of file ttmathbig.h.

References ttmath::Big< exp, man >::Add(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::FromInt(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::Mul(), ttmath::Big< exp, man >::SetLn2(), ttmath::Big< exp, man >::SetNan(), and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::Log(), ttmath::Big< exp, man >::PowFrac(), and ttmath::Big< exp, man >::Sqrt().

2127  {
2128  if( x.IsNan() )
2129  return CheckCarry(1);
2130 
2131  if( x.IsSign() || x.IsZero() )
2132  {
2133  SetNan();
2134  return 2;
2135  }
2136 
2137  Big<exp,man> exponent_temp;
2138  exponent_temp.FromInt( x.exponent );
2139 
2140  // m will be the value of the mantissa in range <1,2)
2141  Big<exp,man> m(x);
2142  m.exponent = -sint(man*TTMATH_BITS_PER_UINT - 1);
2143 
2144  // we must add 'man*TTMATH_BITS_PER_UINT-1' because we've taken it from the mantissa
2145  uint c = exponent_temp.Add(man*TTMATH_BITS_PER_UINT-1);
2146 
2147  LnSurrounding1(m);
2148 
2149  Big<exp,man> ln2;
2150  ln2.SetLn2();
2151  c += exponent_temp.Mul(ln2);
2152  c += Add(exponent_temp);
2153 
2154  return CheckCarry(c);
2155  }
signed long sint
Definition: ttmathtypes.h:243
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
unsigned long uint
Definition: ttmathtypes.h:238
uint Add(Big< exp, man > ss2, bool round=true, bool adding=true)
Definition: ttmathbig.h:930

§ Log()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Log ( const Big< exp, man > &  x,
const Big< exp, man > &  base 
)

Logarithm from 'x' with a 'base'

we're using the formula:

Log(x) with 'base' = ln(x) / ln(base)

return values:

  • 0 - ok
  • 1 - overflow
  • 2 - incorrect argument (x<=0)
  • 3 - incorrect base (a<=0 or a=1)

Definition at line 2171 of file ttmathbig.h.

References ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::Ln(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetOne(), and ttmath::Big< exp, man >::SetZero().

2172  {
2173  if( x.IsNan() || base.IsNan() )
2174  return CheckCarry(1);
2175 
2176  if( x.IsSign() || x.IsZero() )
2177  {
2178  SetNan();
2179  return 2;
2180  }
2181 
2182  Big<exp,man> denominator;;
2183  denominator.SetOne();
2184 
2185  if( base.IsSign() || base.IsZero() || base==denominator )
2186  {
2187  SetNan();
2188  return 3;
2189  }
2190 
2191  if( x == denominator ) // (this is: if x == 1)
2192  {
2193  // log(1) is 0
2194  SetZero();
2195  return 0;
2196  }
2197 
2198  // another error values we've tested at the beginning
2199  // there can only be a carry
2200  uint c = Ln(x);
2201 
2202  c += denominator.Ln(base);
2203  c += Div(denominator);
2204 
2205  return CheckCarry(c);
2206  }
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
uint Ln(const Big< exp, man > &x)
Definition: ttmathbig.h:2126
void SetNan()
Definition: ttmathbig.h:296
uint Div(const Big< exp, man > &ss2, bool round=true)
Definition: ttmathbig.h:1452
unsigned long uint
Definition: ttmathtypes.h:238
void SetZero()
Definition: ttmathbig.h:256

§ Mod()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Mod ( const Big< exp, man > &  ss2)

caltulate the remainder from a division

samples

  • 12.6 mod 3 = 0.6 because 12.6 = 3*4 + 0.6
  • -12.6 mod 3 = -0.6 bacause -12.6 = 3*(-4) + (-0.6)
  • 12.6 mod -3 = 0.6
  • -12.6 mod -3 = -0.6

in other words: this(old) = ss2 * q + this(new)

return value:

  • 0 - ok
  • 1 - carry
  • 2 - improper argument (ss2 is zero)

Definition at line 1521 of file ttmathbig.h.

1522  {
1523  if( this == &ss2 )
1524  {
1525  Big<exp, man> copy_ss2(ss2);
1526  return ModRef(copy_ss2);
1527  }
1528  else
1529  {
1530  return ModRef(ss2);
1531  }
1532  }

§ Mod2()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Mod2 ( ) const

this method returns: 'this' mod 2 (either zero or one)

this method is much faster than using Mod( object_with_value_two )

Definition at line 1541 of file ttmathbig.h.

References ttmath::UInt< value_size >::GetBit(), ttmath::Int< value_size >::ToInt(), and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::PowUInt().

1542  {
1543  if( exponent>sint(0) || exponent<=-sint(man*TTMATH_BITS_PER_UINT) )
1544  return 0;
1545 
1546  sint exp_int = exponent.ToInt();
1547  // 'exp_int' is negative (or zero), we set it as positive
1548  exp_int = -exp_int;
1549 
1550  return mantissa.GetBit(exp_int);
1551  }
signed long sint
Definition: ttmathtypes.h:243
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
uint GetBit(uint bit_index) const
Definition: ttmathuint.h:706
sint ToInt() const
Definition: ttmathint.h:1132

§ Mul()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Mul ( const Big< exp, man > &  ss2,
bool  round = true 
)

§ MulInt()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::MulInt ( sint  ss2)

Multiplication this = this * ss2 (ss2 is sint)

ss2 with a sign

Definition at line 1215 of file ttmathbig.h.

References ttmath::Big< exp, man >::Abs(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::MulUInt(), ttmath::Big< exp, man >::SetSign(), and ttmath::Big< exp, man >::SetZero().

1216  {
1217  if( IsNan() )
1218  return 1;
1219 
1220  if( ss2 == 0 )
1221  {
1222  SetZero();
1223  return 0;
1224  }
1225 
1226  if( IsZero() )
1227  return 0;
1228 
1229  if( IsSign() == (ss2<0) )
1230  {
1231  // the signs are the same (both are either - or +), the result is positive
1232  Abs();
1233  }
1234  else
1235  {
1236  // the signs are different, the result is negative
1237  SetSign();
1238  }
1239 
1240  if( ss2<0 )
1241  ss2 = -ss2;
1242 
1243 
1244  return MulUInt( uint(ss2) );
1245  }
bool IsSign() const
Definition: ttmathbig.h:658
void SetSign()
Definition: ttmathbig.h:726
void Abs()
Definition: ttmathbig.h:682
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
unsigned long uint
Definition: ttmathtypes.h:238
uint MulUInt(uint ss2)
Definition: ttmathbig.h:1161
void SetZero()
Definition: ttmathbig.h:256

§ MulUInt()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::MulUInt ( uint  ss2)

Multiplication this = this * ss2 (ss2 is uint)

ss2 without a sign

Definition at line 1161 of file ttmathbig.h.

References ttmath::Int< value_size >::Add(), ttmath::Big< exp, man >::CheckCarry(), ttmath::UInt< value_size >::CompensationToLeft(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::MulInt(), ttmath::UInt< value_size >::Rcr(), ttmath::Big< exp, man >::SetZero(), ttmath::Big< exp, man >::Standardizing(), ttmath::UInt< value_size >::table, and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::MulInt().

1162  {
1163  UInt<man+1> man_result;
1164  uint i,c = 0;
1165 
1166  if( IsNan() )
1167  return 1;
1168 
1169  if( IsZero() )
1170  return 0;
1171 
1172  if( ss2 == 0 )
1173  {
1174  SetZero();
1175  return 0;
1176  }
1177 
1178  // man_result = mantissa * ss2.mantissa
1179  mantissa.MulInt(ss2, man_result);
1180 
1181  sint bit = UInt<man>::FindLeadingBitInWord(man_result.table[man]); // man - last word
1182 
1183  if( bit!=-1 && uint(bit) > (TTMATH_BITS_PER_UINT/2) )
1184  {
1185  // 'i' will be from 0 to TTMATH_BITS_PER_UINT
1186  i = man_result.CompensationToLeft();
1187  c = exponent.Add( TTMATH_BITS_PER_UINT - i );
1188 
1189  for(i=0 ; i<man ; ++i)
1190  mantissa.table[i] = man_result.table[i+1];
1191  }
1192  else
1193  {
1194  if( bit != -1 )
1195  {
1196  man_result.Rcr(bit+1, 0);
1197  c += exponent.Add(bit+1);
1198  }
1199 
1200  for(i=0 ; i<man ; ++i)
1201  mantissa.table[i] = man_result.table[i];
1202  }
1203 
1204  c += Standardizing();
1205 
1206  return CheckCarry(c);
1207  }
signed long sint
Definition: ttmathtypes.h:243
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
uint table[value_size]
Definition: ttmathuint.h:81
uint MulInt(uint ss2)
Definition: ttmathuint.h:835
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
uint Add(const Int< value_size > &ss2)
Definition: ttmathint.h:220
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
unsigned long uint
Definition: ttmathtypes.h:238
uint Standardizing()
Definition: ttmathbig.h:173
void SetZero()
Definition: ttmathbig.h:256

§ operator &()

template<uint exp, uint man>
Big<exp,man> ttmath::Big< exp, man >::operator& ( const Big< exp, man > &  p2) const

bitwise operators (we do not define bitwise not)

Definition at line 5721 of file ttmathbig.h.

References ttmath::Big< exp, man >::BitAnd(), ttmath::Big< exp, man >::BitOr(), and ttmath::Big< exp, man >::BitXor().

5722  {
5723  Big<exp,man> temp( *this );
5724 
5725  temp.BitAnd(p2);
5726 
5727  return temp;
5728  }

§ operator++() [1/2]

template<uint exp, uint man>
Big<exp,man>& ttmath::Big< exp, man >::operator++ ( )

Prefix operator e.g ++variable

Definition at line 5674 of file ttmathbig.h.

5675  {
5676  AddOne();
5677 
5678  return *this;
5679  }

§ operator++() [2/2]

template<uint exp, uint man>
Big<exp,man> ttmath::Big< exp, man >::operator++ ( int  )

Postfix operator e.g variable++

Definition at line 5685 of file ttmathbig.h.

5686  {
5687  Big<exp,man> temp( *this );
5688 
5689  AddOne();
5690 
5691  return temp;
5692  }

§ operator-()

template<uint exp, uint man>
Big<exp,man> ttmath::Big< exp, man >::operator- ( ) const

standard mathematical operators

an operator for changing the sign

this method is not changing 'this' but the changed value is returned

Definition at line 5590 of file ttmathbig.h.

References ttmath::Big< exp, man >::Add(), ttmath::Big< exp, man >::ChangeSign(), ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::Mul(), and ttmath::Big< exp, man >::Sub().

5591  {
5592  Big<exp,man> temp(*this);
5593 
5594  temp.ChangeSign();
5595 
5596  return temp;
5597  }

§ operator=() [1/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( sint  value)

an operator= for converting 'sint' to this class

Definition at line 3101 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromInt().

Referenced by ttmath::Big< exp, man >::Big().

3102  {
3103  FromInt(value);
3104 
3105  return *this;
3106  }
uint FromInt(uint value)
Definition: ttmathbig.h:2546

§ operator=() [2/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( uint  value)

an operator= for converting 'uint' to this class

Definition at line 3112 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromUInt().

3113  {
3114  FromUInt(value);
3115 
3116  return *this;
3117  }
uint FromUInt(uint value)
Definition: ttmathbig.h:2520

§ operator=() [3/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( float  value)

an operator= for converting 'float' to this class

Definition at line 3123 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromFloat().

3124  {
3125  FromFloat(value);
3126 
3127  return *this;
3128  }
uint FromFloat(float value)
Definition: ttmathbig.h:2815

§ operator=() [4/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( double  value)

an operator= for converting 'double' to this class

Definition at line 3134 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromDouble().

3135  {
3136  FromDouble(value);
3137 
3138  return *this;
3139  }
uint FromDouble(double value)
Definition: ttmathbig.h:2718

§ operator=() [5/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( unsigned int  value)

an operator= for converting 32 bit unsigned int to this class this operator is created only on a 64bit platform***

Definition at line 3440 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromUInt().

3441  {
3442  FromUInt(value);
3443 
3444  return *this;
3445  }
uint FromUInt(uint value)
Definition: ttmathbig.h:2520

§ operator=() [6/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( signed int  value)

an operator for converting 32 bit signed int to this class this operator is created only on a 64bit platform***

Definition at line 3462 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromInt().

3463  {
3464  FromInt(value);
3465 
3466  return *this;
3467  }
uint FromInt(uint value)
Definition: ttmathbig.h:2546

§ operator=() [7/14]

template<uint exp, uint man>
template<uint int_size>
Big<exp,man>& ttmath::Big< exp, man >::operator= ( const Int< int_size > &  value)

an operator= for converting from 'Int<int_size>' to this class

Definition at line 3568 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromInt().

3569  {
3570  FromInt(value);
3571 
3572  return *this;
3573  }
uint FromInt(uint value)
Definition: ttmathbig.h:2546

§ operator=() [8/14]

template<uint exp, uint man>
template<uint int_size>
Big<exp,man>& ttmath::Big< exp, man >::operator= ( const UInt< int_size > &  value)

an operator= for converting from 'UInt<int_size>' to this class

Definition at line 3590 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromUInt().

3591  {
3592  FromUInt(value);
3593 
3594  return *this;
3595  }
uint FromUInt(uint value)
Definition: ttmathbig.h:2520

§ operator=() [9/14]

template<uint exp, uint man>
template<uint another_exp, uint another_man>
Big<exp,man>& ttmath::Big< exp, man >::operator= ( const Big< another_exp, another_man > &  value)

an operator= for converting from 'Big<another_exp, another_man>' to this class

Definition at line 3612 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromBig().

3613  {
3614  FromBig(value);
3615 
3616  return *this;
3617  }
uint FromBig(const Big< another_exp, another_man > &another)
Definition: ttmathbig.h:2222

§ operator=() [10/14]

template<uint exp, uint man>
Big<exp,man>& ttmath::Big< exp, man >::operator= ( const Big< exp, man > &  value)

the default assignment operator

Definition at line 3667 of file ttmathbig.h.

3668  {
3669  info = value.info;
3670  exponent = value.exponent;
3671  mantissa = value.mantissa;
3672 
3673  return *this;
3674  }

§ operator=() [11/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( const char *  string)

an operator= for converting a string into its value

Definition at line 5321 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

5322  {
5323  FromString( string );
5324 
5325  return *this;
5326  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ operator=() [12/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( const std::string &  string)

an operator= for converting a string into its value

Definition at line 5332 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

5333  {
5334  FromString( string.c_str() );
5335 
5336  return *this;
5337  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ operator=() [13/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( const wchar_t *  string)

an operator= for converting a string into its value

Definition at line 5364 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

5365  {
5366  FromString( string );
5367 
5368  return *this;
5369  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ operator=() [14/14]

template<uint exp, uint man>
Big<exp, man>& ttmath::Big< exp, man >::operator= ( const std::wstring &  string)

an operator= for converting a string into its value

Definition at line 5375 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromString().

5376  {
5377  FromString( string.c_str() );
5378 
5379  return *this;
5380  }
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
Definition: ttmathbig.h:4931

§ Pow() [1/3]

template<uint exp, uint man>
template<uint pow_size>
uint ttmath::Big< exp, man >::Pow ( UInt< pow_size >  pow)

power this = this ^ pow (pow without a sign)

binary algorithm (r-to-l)

return values:

  • 0 - ok
  • 1 - carry
  • 2 - incorrect arguments (0^0)

Definition at line 1566 of file ttmathbig.h.

References ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::IsZero(), ttmath::Big< exp, man >::Mul(), ttmath::UInt< value_size >::Rcr(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetOne(), and ttmath::UInt< value_size >::table.

Referenced by ttmath::Big< exp, man >::FromString(), and ttmath::Big< exp, man >::Pow().

1567  {
1568  if( IsNan() )
1569  return 1;
1570 
1571  if( IsZero() )
1572  {
1573  if( pow.IsZero() )
1574  {
1575  // we don't define zero^zero
1576  SetNan();
1577  return 2;
1578  }
1579 
1580  // 0^(+something) is zero
1581  return 0;
1582  }
1583 
1584  Big<exp, man> start(*this);
1585  Big<exp, man> result;
1586  result.SetOne();
1587  uint c = 0;
1588 
1589  while( !c )
1590  {
1591  if( pow.table[0] & 1 )
1592  c += result.Mul(start);
1593 
1594  pow.Rcr(1);
1595 
1596  if( pow.IsZero() )
1597  break;
1598 
1599  c += start.Mul(start);
1600  }
1601 
1602  *this = result;
1603 
1604  return CheckCarry(c);
1605  }
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
unsigned long uint
Definition: ttmathtypes.h:238

§ Pow() [2/3]

template<uint exp, uint man>
template<uint pow_size>
uint ttmath::Big< exp, man >::Pow ( Int< pow_size >  pow)

power this = this ^ pow p can be negative

return values:

  • 0 - ok
  • 1 - carry
  • 2 - incorrect arguments 0^0 or 0^(-something)

Definition at line 1618 of file ttmathbig.h.

References ttmath::Int< value_size >::ChangeSign(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::IsNan(), ttmath::Int< value_size >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::Pow(), ttmath::Big< exp, man >::SetNan(), and ttmath::Big< exp, man >::SetOne().

1619  {
1620  if( IsNan() )
1621  return 1;
1622 
1623  if( !pow.IsSign() )
1624  return Pow( UInt<pow_size>(pow) );
1625 
1626  if( IsZero() )
1627  {
1628  // if 'p' is negative then
1629  // 'this' must be different from zero
1630  SetNan();
1631  return 2;
1632  }
1633 
1634  uint c = pow.ChangeSign();
1635 
1636  Big<exp, man> t(*this);
1637  c += t.Pow( UInt<pow_size>(pow) ); // here can only be a carry (return:1)
1638 
1639  SetOne();
1640  c += Div(t);
1641 
1642  return CheckCarry(c);
1643  }
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
uint Pow(UInt< pow_size > pow)
Definition: ttmathbig.h:1566
void SetNan()
Definition: ttmathbig.h:296
void SetOne()
Definition: ttmathbig.h:271
uint Div(const Big< exp, man > &ss2, bool round=true)
Definition: ttmathbig.h:1452
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
unsigned long uint
Definition: ttmathtypes.h:238

§ Pow() [3/3]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Pow ( const Big< exp, man > &  pow)

power this = this ^ pow pow can be negative and with fraction

return values:

  • 0 - ok
  • 1 - carry
  • 2 - incorrect argument ('this' or 'pow')

Definition at line 1779 of file ttmathbig.h.

References ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::IsInteger(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::PowFrac(), ttmath::Big< exp, man >::PowInt(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetZero(), and TTMATH_BITS_PER_UINT.

1780  {
1781  if( IsNan() || pow.IsNan() )
1782  return CheckCarry(1);
1783 
1784  if( IsZero() )
1785  {
1786  // 0^pow will be 0 only for pow>0
1787  if( pow.IsSign() || pow.IsZero() )
1788  {
1789  SetNan();
1790  return 2;
1791  }
1792 
1793  SetZero();
1794 
1795  return 0;
1796  }
1797 
1798  if( pow.exponent>-sint(man*TTMATH_BITS_PER_UINT) && pow.exponent<=0 )
1799  {
1800  if( pow.IsInteger() )
1801  return PowInt( pow );
1802  }
1803 
1804  return PowFrac(pow);
1805  }
signed long sint
Definition: ttmathtypes.h:243
uint PowFrac(const Big< exp, man > &pow)
Definition: ttmathbig.h:1749
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
uint PowInt(const Big< exp, man > &pow)
Definition: ttmathbig.h:1713
void SetZero()
Definition: ttmathbig.h:256

§ PowFrac()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::PowFrac ( const Big< exp, man > &  pow)

power this = this ^ pow this must be greater than zero (this > 0) pow can be negative and with fraction

return values:

  • 0 - ok
  • 1 - carry
  • 2 - incorrect argument ('this' <= 0)

Definition at line 1749 of file ttmathbig.h.

References ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::Exp(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::Ln(), ttmath::Big< exp, man >::Mul(), and ttmath::Big< exp, man >::SetNan().

Referenced by ttmath::Big< exp, man >::Pow().

1750  {
1751  if( IsNan() || pow.IsNan() )
1752  return CheckCarry(1);
1753 
1754  Big<exp, man> temp;
1755  uint c = temp.Ln(*this);
1756 
1757  if( c != 0 ) // can be 2 from Ln()
1758  {
1759  SetNan();
1760  return c;
1761  }
1762 
1763  c += temp.Mul(pow);
1764  c += Exp(temp);
1765 
1766  return CheckCarry(c);
1767  }
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
uint Exp(const Big< exp, man > &x)
Definition: ttmathbig.h:1948
bool IsNan() const
Definition: ttmathbig.h:667
unsigned long uint
Definition: ttmathtypes.h:238

§ PowInt()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::PowInt ( const Big< exp, man > &  pow)

power this = this ^ [pow] pow is treated as a value without a fraction pow can be negative

return values:

  • 0 - ok
  • 1 - carry
  • 2 - incorrect arguments 0^0 or 0^(-something)

Definition at line 1713 of file ttmathbig.h.

References ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::PowUInt(), ttmath::Big< exp, man >::SetNan(), and ttmath::Big< exp, man >::SetOne().

Referenced by ttmath::Big< exp, man >::Pow().

1714  {
1715  if( IsNan() || pow.IsNan() )
1716  return CheckCarry(1);
1717 
1718  if( !pow.IsSign() )
1719  return PowUInt(pow);
1720 
1721  if( IsZero() )
1722  {
1723  // if 'pow' is negative then
1724  // 'this' must be different from zero
1725  SetNan();
1726  return 2;
1727  }
1728 
1729  Big<exp, man> temp(*this);
1730  uint c = temp.PowUInt(pow); // here can only be a carry (result:1)
1731 
1732  SetOne();
1733  c += Div(temp);
1734 
1735  return CheckCarry(c);
1736  }
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
void SetOne()
Definition: ttmathbig.h:271
uint PowUInt(Big< exp, man > pow)
Definition: ttmathbig.h:1657
uint Div(const Big< exp, man > &ss2, bool round=true)
Definition: ttmathbig.h:1452
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
unsigned long uint
Definition: ttmathtypes.h:238

§ PowUInt()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::PowUInt ( Big< exp, man >  pow)

power this = this ^ abs([pow]) pow is treated as a value without a sign and without a fraction if pow has a sign then the method pow.Abs() is used if pow has a fraction the fraction is skipped (not used in calculation)

return values:

  • 0 - ok
  • 1 - carry
  • 2 - incorrect arguments (0^0)

Definition at line 1657 of file ttmathbig.h.

References ttmath::Big< exp, man >::Abs(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::Mod2(), ttmath::Big< exp, man >::Mul(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetOne(), and ttmath::Int< value_size >::SubOne().

Referenced by ttmath::Big< exp, man >::Exp(), and ttmath::Big< exp, man >::PowInt().

1658  {
1659  if( IsNan() || pow.IsNan() )
1660  return CheckCarry(1);
1661 
1662  if( IsZero() )
1663  {
1664  if( pow.IsZero() )
1665  {
1666  SetNan();
1667  return 2;
1668  }
1669 
1670  // 0^(+something) is zero
1671  return 0;
1672  }
1673 
1674  if( pow.IsSign() )
1675  pow.Abs();
1676 
1677  Big<exp, man> start(*this);
1678  Big<exp, man> result;
1679  Big<exp, man> one;
1680  uint c = 0;
1681  one.SetOne();
1682  result = one;
1683 
1684  while( !c )
1685  {
1686  if( pow.Mod2() )
1687  c += result.Mul(start);
1688 
1689  c += pow.exponent.SubOne();
1690 
1691  if( pow < one )
1692  break;
1693 
1694  c += start.Mul(start);
1695  }
1696 
1697  *this = result;
1698 
1699  return CheckCarry(c);
1700  }
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
unsigned long uint
Definition: ttmathtypes.h:238

§ RemainFraction()

template<uint exp, uint man>
void ttmath::Big< exp, man >::RemainFraction ( )

this method remains only a fraction from the value

samples:

  • 30.56 will be 0.56
  • -12.67 will be -0.67

Definition at line 5824 of file ttmathbig.h.

References ttmath::Big< exp, man >::IsNan(), ttmath::Int< value_size >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::Rcl(), ttmath::Big< exp, man >::SetZero(), ttmath::Big< exp, man >::Standardizing(), ttmath::Int< value_size >::Sub(), and ttmath::Int< value_size >::ToInt().

5825  {
5826  if( IsNan() || IsZero() )
5827  return;
5828 
5829  if( !exponent.IsSign() )
5830  {
5831  // exponent >= 0 -- the value doesn't have any fractions
5832  // we return zero
5833  SetZero();
5834  return;
5835  }
5836 
5837  if( exponent <= -sint(man*TTMATH_BITS_PER_UINT) )
5838  {
5839  // the value is from (-1,1)
5840  // we don't make anything with the value
5841  return;
5842  }
5843 
5844  // e will be from (-man*TTMATH_BITS_PER_UINT, 0)
5845  sint e = exponent.ToInt();
5846 
5847  sint how_many_bits_leave = sint(man*TTMATH_BITS_PER_UINT) + e; // there'll be a subtraction -- e is negative
5848  mantissa.Rcl( how_many_bits_leave, 0);
5849 
5850  // there'll not be a carry because the exponent is too small
5851  exponent.Sub( how_many_bits_leave );
5852 
5853  // we must call Standardizing() here
5854  Standardizing();
5855  }
signed long sint
Definition: ttmathtypes.h:243
uint Rcl(uint bits, uint c=0)
Definition: ttmathuint.h:460
bool IsZero() const
Definition: ttmathbig.h:648
bool IsSign() const
Definition: ttmathint.h:156
bool IsNan() const
Definition: ttmathbig.h:667
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
uint Standardizing()
Definition: ttmathbig.h:173
void SetZero()
Definition: ttmathbig.h:256
uint Sub(const Int< value_size > &ss2)
Definition: ttmathint.h:299
sint ToInt() const
Definition: ttmathint.h:1132

§ Round()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Round ( )

this method rounds to the nearest integer value (it returns a carry if it was)

samples:

  • 2.3 = 2
  • 2.8 = 3
  • -2.3 = -2
  • -2.8 = 3

Definition at line 5911 of file ttmathbig.h.

References ttmath::Big< exp, man >::Add(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::Set05(), ttmath::Big< exp, man >::SkipFraction(), ttmath::Big< exp, man >::Sub(), and ttmath::Big< exp, man >::ToString().

Referenced by ttmath::Big< exp, man >::Sqrt().

5912  {
5913  Big<exp,man> half;
5914  uint c;
5915 
5916  if( IsNan() )
5917  return 1;
5918 
5919  if( IsZero() )
5920  return 0;
5921 
5922  half.Set05();
5923 
5924  if( IsSign() )
5925  {
5926  // 'this' is < 0
5927  c = Sub( half );
5928  }
5929  else
5930  {
5931  // 'this' is > 0
5932  c = Add( half );
5933  }
5934 
5935  SkipFraction();
5936 
5937  return CheckCarry(c);
5938  }
bool IsSign() const
Definition: ttmathbig.h:658
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
bool IsZero() const
Definition: ttmathbig.h:648
uint Sub(const Big< exp, man > &ss2, bool round=true)
Definition: ttmathbig.h:978
bool IsNan() const
Definition: ttmathbig.h:667
unsigned long uint
Definition: ttmathtypes.h:238
uint Add(Big< exp, man > ss2, bool round=true, bool adding=true)
Definition: ttmathbig.h:930
void SkipFraction()
Definition: ttmathbig.h:5790

§ Set05()

template<uint exp, uint man>
void ttmath::Big< exp, man >::Set05 ( )

this method sets value 0.5

Definition at line 285 of file ttmathbig.h.

References ttmath::Big< exp, man >::SetOne(), and ttmath::Int< value_size >::SubOne().

Referenced by ttmath::Big< exp, man >::Round().

286  {
287  SetOne();
288  exponent.SubOne();
289  }
void SetOne()
Definition: ttmathbig.h:271
uint SubOne()
Definition: ttmathint.h:340

§ Set05Pi()

template<uint exp, uint man>
void ttmath::Big< exp, man >::Set05Pi ( )

this method sets the value of 0.5 * pi

Definition at line 406 of file ttmathbig.h.

References TTMATH_BITS_PER_UINT.

407  {
408  // IMPROVE ME
409  // give some compiler-time warning when the size of mantissa is greater than the builtin size of the mantissa pi
410  SetMantissaPi();
411  info = 0;
412  exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 1;
413  }
signed long sint
Definition: ttmathtypes.h:243
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253

§ Set2Pi()

template<uint exp, uint man>
void ttmath::Big< exp, man >::Set2Pi ( )

this method sets the value of 2 * pi

Definition at line 419 of file ttmathbig.h.

References TTMATH_BITS_PER_UINT.

420  {
421  // IMPROVE ME
422  // give some compiler-time warning when the size of mantissa is greater than the builtin size of the mantissa pi
423  SetMantissaPi();
424  info = 0;
425  exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 3;
426  }
signed long sint
Definition: ttmathtypes.h:243
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253

§ SetE()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetE ( )

this method sets the value of e (the base of the natural logarithm)

Definition at line 433 of file ttmathbig.h.

References ttmath::UInt< value_size >::SetFromTable(), and TTMATH_BITS_PER_UINT.

434  {
435  static const unsigned int temp_table[] = {
436  0xadf85458, 0xa2bb4a9a, 0xafdc5620, 0x273d3cf1, 0xd8b9c583, 0xce2d3695, 0xa9e13641, 0x146433fb,
437  0xcc939dce, 0x249b3ef9, 0x7d2fe363, 0x630c75d8, 0xf681b202, 0xaec4617a, 0xd3df1ed5, 0xd5fd6561,
438  0x2433f51f, 0x5f066ed0, 0x85636555, 0x3ded1af3, 0xb557135e, 0x7f57c935, 0x984f0c70, 0xe0e68b77,
439  0xe2a689da, 0xf3efe872, 0x1df158a1, 0x36ade735, 0x30acca4f, 0x483a797a, 0xbc0ab182, 0xb324fb61,
440  0xd108a94b, 0xb2c8e3fb, 0xb96adab7, 0x60d7f468, 0x1d4f42a3, 0xde394df4, 0xae56ede7, 0x6372bb19,
441  0x0b07a7c8, 0xee0a6d70, 0x9e02fce1, 0xcdf7e2ec, 0xc03404cd, 0x28342f61, 0x9172fe9c, 0xe98583ff,
442  0x8e4f1232, 0xeef28183, 0xc3fe3b1b, 0x4c6fad73, 0x3bb5fcbc, 0x2ec22005, 0xc58ef183, 0x7d1683b2,
443  0xc6f34a26, 0xc1b2effa, 0x886b4238, 0x611fcfdc, 0xde355b3b, 0x6519035b, 0xbc34f4de, 0xf99c0238,
444  0x61b46fc9, 0xd6e6c907, 0x7ad91d26, 0x91f7f7ee, 0x598cb0fa, 0xc186d91c, 0xaefe1309, 0x85139270,
445  0xb4130c93, 0xbc437944, 0xf4fd4452, 0xe2d74dd3, 0x64f2e21e, 0x71f54bff, 0x5cae82ab, 0x9c9df69e,
446  0xe86d2bc5, 0x22363a0d, 0xabc52197, 0x9b0deada, 0x1dbf9a42, 0xd5c4484e, 0x0abcd06b, 0xfa53ddef,
447  0x3c1b20ee, 0x3fd59d7c, 0x25e41d2b, 0x669e1ef1, 0x6e6f52c3, 0x164df4fb, 0x7930e9e4, 0xe58857b6,
448  0xac7d5f42, 0xd69f6d18, 0x7763cf1d, 0x55034004, 0x87f55ba5, 0x7e31cc7a, 0x7135c886, 0xefb4318a,
449  0xed6a1e01, 0x2d9e6832, 0xa907600a, 0x918130c4, 0x6dc778f9, 0x71ad0038, 0x092999a3, 0x33cb8b7a,
450  0x1a1db93d, 0x7140003c, 0x2a4ecea9, 0xf98d0acc, 0x0a8291cd, 0xcec97dcf, 0x8ec9b55a, 0x7f88a46b,
451  0x4db5a851, 0xf44182e1, 0xc68a007e, 0x5e0dd902, 0x0bfd64b6, 0x45036c7a, 0x4e677d2c, 0x38532a3a,
452  0x23ba4442, 0xcaf53ea6, 0x3bb45432, 0x9b7624c8, 0x917bdd64, 0xb1c0fd4c, 0xb38e8c33, 0x4c701c3a,
453  0xcdad0657, 0xfccfec71, 0x9b1f5c3e, 0x4e46041f, 0x388147fb, 0x4cfdb477, 0xa52471f7, 0xa9a96910,
454  0xb855322e, 0xdb6340d8, 0xa00ef092, 0x350511e3, 0x0abec1ff, 0xf9e3a26e, 0x7fb29f8c, 0x183023c3,
455  0x587e38da, 0x0077d9b4, 0x763e4e4b, 0x94b2bbc1, 0x94c6651e, 0x77caf992, 0xeeaac023, 0x2a281bf6,
456  0xb3a739c1, 0x22611682, 0x0ae8db58, 0x47a67cbe, 0xf9c9091b, 0x462d538c, 0xd72b0374, 0x6ae77f5e,
457  0x62292c31, 0x1562a846, 0x505dc82d, 0xb854338a, 0xe49f5235, 0xc95b9117, 0x8ccf2dd5, 0xcacef403,
458  0xec9d1810, 0xc6272b04, 0x5b3b71f9, 0xdc6b80d6, 0x3fdd4a8e, 0x9adb1e69, 0x62a69526, 0xd43161c1,
459  0xa41d570d, 0x7938dad4, 0xa40e329c, 0xcff46aaa, 0x36ad004c, 0xf600c838, 0x1e425a31, 0xd951ae64,
460  0xfdb23fce, 0xc9509d43, 0x687feb69, 0xedd1cc5e, 0x0b8cc3bd, 0xf64b10ef, 0x86b63142, 0xa3ab8829,
461  0x555b2f74, 0x7c932665, 0xcb2c0f1c, 0xc01bd702, 0x29388839, 0xd2af05e4, 0x54504ac7, 0x8b758282,
462  0x2846c0ba, 0x35c35f5c, 0x59160cc0, 0x46fd8251, 0x541fc68c, 0x9c86b022, 0xbb709987, 0x6a460e74,
463  0x51a8a931, 0x09703fee, 0x1c217e6c, 0x3826e52c, 0x51aa691e, 0x0e423cfc, 0x99e9e316, 0x50c1217b,
464  0x624816cd, 0xad9a95f9, 0xd5b80194, 0x88d9c0a0, 0xa1fe3075, 0xa577e231, 0x83f81d4a, 0x3f2fa457,
465  0x1efc8ce0, 0xba8a4fe8, 0xb6855dfe, 0x72b0a66e, 0xded2fbab, 0xfbe58a30, 0xfafabe1c, 0x5d71a87e,
466  0x2f741ef8, 0xc1fe86fe, 0xa6bbfde5, 0x30677f0d, 0x97d11d49, 0xf7a8443d, 0x0822e506, 0xa9f4614e,
467  0x011e2a94, 0x838ff88c, 0xd68c8bb7, 0xc51eef6d, 0x49ea8ab4, 0xf2c3df5b, 0xb4e0735a, 0xb0d68749
468  // 0x2fe26dd4, ...
469  // 256 32bit words for the mantissa -- about 2464 valid decimal digits
470  };
471 
472  // above value was calculated using Big<1,400> type on a 32bit platform
473  // and then the first 256 words were taken,
474  // the calculating was made by using ExpSurrounding0(1) method
475  // which took 1420 iterations
476  // (the result was compared with e taken from http://antwrp.gsfc.nasa.gov/htmltest/gifcity/e.2mil)
477  // (TTMATH_BUILTIN_VARIABLES_SIZE on 32bit platform should have the value 256,
478  // and on 64bit platform value 128 (256/2=128))
479 
480  mantissa.SetFromTable(temp_table, sizeof(temp_table) / sizeof(int));
481  exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 2;
482  info = 0;
483  }
void SetFromTable(const unsigned int *temp_table, uint temp_table_len)
Definition: ttmathuint.h:325
signed long sint
Definition: ttmathtypes.h:243
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253

§ SetInfoBit()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetInfoBit ( unsigned char  bit)

this method sets a specific bit in the 'info' variable

bit is one of: TTMATH_BIG_SIGN, TTMATH_BIG_NAN etc.

Definition at line 236 of file ttmathbig.h.

Referenced by ttmath::Big< exp, man >::ChangeSign(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetSign(), and ttmath::Big< exp, man >::Standardizing().

237  {
238  info = info | bit;
239  }

§ SetLn10()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetLn10 ( )

this method sets the value of ln(10) the natural logarithm from 10

I introduced this constant especially to make the conversion ToString() being faster. In fact the method ToString() is keeping values of logarithms it has calculated but it must calculate the logarithm at least once. If a program, which uses this library, is running for a long time this would be ok, but for programs which are running shorter, for example for CGI applications which only once are printing values, this would be much inconvenience. Then if we're printing with base (radix) 10 and the mantissa of our value is smaller than or equal to TTMATH_BUILTIN_VARIABLES_SIZE we don't calculate the logarithm but take it from this constant.

Definition at line 558 of file ttmathbig.h.

References ttmath::UInt< value_size >::SetFromTable(), and TTMATH_BITS_PER_UINT.

559  {
560  static const unsigned int temp_table[] = {
561  0x935d8ddd, 0xaaa8ac16, 0xea56d62b, 0x82d30a28, 0xe28fecf9, 0xda5df90e, 0x83c61e82, 0x01f02d72,
562  0x962f02d7, 0xb1a8105c, 0xcc70cbc0, 0x2c5f0d68, 0x2c622418, 0x410be2da, 0xfb8f7884, 0x02e516d6,
563  0x782cf8a2, 0x8a8c911e, 0x765aa6c3, 0xb0d831fb, 0xef66ceb0, 0x4ab3c6fa, 0x5161bb49, 0xd219c7bb,
564  0xca67b35b, 0x23605085, 0x8e93368d, 0x44789c4f, 0x5b08b057, 0xd5ede20f, 0x469ea58e, 0x9305e981,
565  0xe2478fca, 0xad3aee98, 0x9cd5b42e, 0x6a271619, 0xa47ecb26, 0x978c5d4f, 0xdb1d28ea, 0x57d4fdc0,
566  0xe40bf3cc, 0x1e14126a, 0x45765cde, 0x268339db, 0xf47fa96d, 0xeb271060, 0xaf88486e, 0xa9b7401e,
567  0x3dfd3c51, 0x748e6d6e, 0x3848c8d2, 0x5faf1bca, 0xe88047f1, 0x7b0d9b50, 0xa949eaaa, 0xdf69e8a5,
568  0xf77e3760, 0x4e943960, 0xe38a5700, 0xffde2db1, 0xad6bfbff, 0xd821ba0a, 0x4cb0466d, 0x61ba648e,
569  0xef99c8e5, 0xf6974f36, 0x3982a78c, 0xa45ddfc8, 0x09426178, 0x19127a6e, 0x3b70fcda, 0x2d732d47,
570  0xb5e4b1c8, 0xc0e5a10a, 0xaa6604a5, 0x324ec3dc, 0xbc64ea80, 0x6e198566, 0x1f1d366c, 0x20663834,
571  0x4d5e843f, 0x20642b97, 0x0a62d18e, 0x478f7bd5, 0x8fcd0832, 0x4a7b32a6, 0xdef85a05, 0xeb56323a,
572  0x421ef5e0, 0xb00410a0, 0xa0d9c260, 0x794a976f, 0xf6ff363d, 0xb00b6b33, 0xf42c58de, 0xf8a3c52d,
573  0xed69b13d, 0xc1a03730, 0xb6524dc1, 0x8c167e86, 0x99d6d20e, 0xa2defd2b, 0xd006f8b4, 0xbe145a2a,
574  0xdf3ccbb3, 0x189da49d, 0xbc1261c8, 0xb3e4daad, 0x6a36cecc, 0xb2d5ae5b, 0x89bf752f, 0xb5dfb353,
575  0xff3065c4, 0x0cfceec8, 0x1be5a9a9, 0x67fddc57, 0xc4b83301, 0x006bf062, 0x4b40ed7a, 0x56c6cdcd,
576  0xa2d6fe91, 0x388e9e3e, 0x48a93f5f, 0x5e3b6eb4, 0xb81c4a5b, 0x53d49ea6, 0x8e668aea, 0xba83c7f8,
577  0xfb5f06c3, 0x58ac8f70, 0xfa9d8c59, 0x8c574502, 0xbaf54c96, 0xc84911f0, 0x0482d095, 0x1a0af022,
578  0xabbab080, 0xec97efd3, 0x671e4e0e, 0x52f166b6, 0xcd5cd226, 0x0dc67795, 0x2e1e34a3, 0xf799677f,
579  0x2c1d48f1, 0x2944b6c5, 0x2ba1307e, 0x704d67f9, 0x1c1035e4, 0x4e927c63, 0x03cf12bf, 0xe2cd2e31,
580  0xf8ee4843, 0x344d51b0, 0xf37da42b, 0x9f0b0fd9, 0x134fb2d9, 0xf815e490, 0xd966283f, 0x23962766,
581  0xeceab1e4, 0xf3b5fc86, 0x468127e2, 0xb606d10d, 0x3a45f4b6, 0xb776102d, 0x2fdbb420, 0x80c8fa84,
582  0xd0ff9f45, 0xc58aef38, 0xdb2410fd, 0x1f1cebad, 0x733b2281, 0x52ca5f36, 0xddf29daa, 0x544334b8,
583  0xdeeaf659, 0x4e462713, 0x1ed485b4, 0x6a0822e1, 0x28db471c, 0xa53938a8, 0x44c3bef7, 0xf35215c8,
584  0xb382bc4e, 0x3e4c6f15, 0x6285f54c, 0x17ab408e, 0xccbf7f5e, 0xd16ab3f6, 0xced2846d, 0xf457e14f,
585  0xbb45d9c5, 0x646ad497, 0xac697494, 0x145de32e, 0x93907128, 0xd263d521, 0x79efb424, 0xd64651d6,
586  0xebc0c9f0, 0xbb583a44, 0xc6412c84, 0x85bb29a6, 0x4d31a2cd, 0x92954469, 0xa32b1abd, 0xf7f5202c,
587  0xa4aa6c93, 0x2e9b53cf, 0x385ab136, 0x2741f356, 0x5de9c065, 0x6009901c, 0x88abbdd8, 0x74efcf73,
588  0x3f761ad4, 0x35f3c083, 0xfd6b8ee0, 0x0bef11c7, 0xc552a89d, 0x58ce4a21, 0xd71e54f2, 0x4157f6c7,
589  0xd4622316, 0xe98956d7, 0x450027de, 0xcbd398d8, 0x4b98b36a, 0x0724c25c, 0xdb237760, 0xe9324b68,
590  0x7523e506, 0x8edad933, 0x92197f00, 0xb853a326, 0xb330c444, 0x65129296, 0x34bc0670, 0xe177806d,
591  0xe338dac4, 0x5537492a, 0xe19add83, 0xcf45000f, 0x5b423bce, 0x6497d209, 0xe30e18a1, 0x3cbf0687,
592  0x67973103, 0xd9485366, 0x81506bba, 0x2e93a9a4, 0x7dd59d3f, 0xf17cd746, 0x8c2075be, 0x552a4348 // last one was: 0x552a4347
593  // 0xb4a638ef, ...
594  //(the last word 0x552a4347 was rounded up because the next one is 0xb4a638ef -- first bit is one 0xb..)
595  // 256 32bit words for the mantissa -- about 2464 valid digits (decimal)
596  };
597 
598  // above value was calculated using Big<1,400> type on a 32bit platform
599  // and then the first 256 32bit words were taken,
600  // the calculating was made by using LnSurrounding1(10) method
601  // which took 22080 iterations
602  // (the result was compared with ln(10) taken from http://ja0hxv.calico.jp/pai/estart.html)
603  // (the formula used in LnSurrounding1(x) converges badly when
604  // the x is greater than one but in fact we can use it, only the
605  // number of iterations will be greater)
606  // (TTMATH_BUILTIN_VARIABLES_SIZE on 32bit platform should have the value 256,
607  // and on 64bit platform value 128 (256/2=128))
608 
609  mantissa.SetFromTable(temp_table, sizeof(temp_table) / sizeof(int));
610  exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 2;
611  info = 0;
612  }
void SetFromTable(const unsigned int *temp_table, uint temp_table_len)
Definition: ttmathuint.h:325
signed long sint
Definition: ttmathtypes.h:243
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253

§ SetLn2()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetLn2 ( )

this method sets the value of ln(2) the natural logarithm from 2

Definition at line 490 of file ttmathbig.h.

References ttmath::UInt< value_size >::SetFromTable(), and TTMATH_BITS_PER_UINT.

Referenced by ttmath::Big< exp, man >::Ln().

491  {
492  static const unsigned int temp_table[] = {
493  0xb17217f7, 0xd1cf79ab, 0xc9e3b398, 0x03f2f6af, 0x40f34326, 0x7298b62d, 0x8a0d175b, 0x8baafa2b,
494  0xe7b87620, 0x6debac98, 0x559552fb, 0x4afa1b10, 0xed2eae35, 0xc1382144, 0x27573b29, 0x1169b825,
495  0x3e96ca16, 0x224ae8c5, 0x1acbda11, 0x317c387e, 0xb9ea9bc3, 0xb136603b, 0x256fa0ec, 0x7657f74b,
496  0x72ce87b1, 0x9d6548ca, 0xf5dfa6bd, 0x38303248, 0x655fa187, 0x2f20e3a2, 0xda2d97c5, 0x0f3fd5c6,
497  0x07f4ca11, 0xfb5bfb90, 0x610d30f8, 0x8fe551a2, 0xee569d6d, 0xfc1efa15, 0x7d2e23de, 0x1400b396,
498  0x17460775, 0xdb8990e5, 0xc943e732, 0xb479cd33, 0xcccc4e65, 0x9393514c, 0x4c1a1e0b, 0xd1d6095d,
499  0x25669b33, 0x3564a337, 0x6a9c7f8a, 0x5e148e82, 0x074db601, 0x5cfe7aa3, 0x0c480a54, 0x17350d2c,
500  0x955d5179, 0xb1e17b9d, 0xae313cdb, 0x6c606cb1, 0x078f735d, 0x1b2db31b, 0x5f50b518, 0x5064c18b,
501  0x4d162db3, 0xb365853d, 0x7598a195, 0x1ae273ee, 0x5570b6c6, 0x8f969834, 0x96d4e6d3, 0x30af889b,
502  0x44a02554, 0x731cdc8e, 0xa17293d1, 0x228a4ef9, 0x8d6f5177, 0xfbcf0755, 0x268a5c1f, 0x9538b982,
503  0x61affd44, 0x6b1ca3cf, 0x5e9222b8, 0x8c66d3c5, 0x422183ed, 0xc9942109, 0x0bbb16fa, 0xf3d949f2,
504  0x36e02b20, 0xcee886b9, 0x05c128d5, 0x3d0bd2f9, 0x62136319, 0x6af50302, 0x0060e499, 0x08391a0c,
505  0x57339ba2, 0xbeba7d05, 0x2ac5b61c, 0xc4e9207c, 0xef2f0ce2, 0xd7373958, 0xd7622658, 0x901e646a,
506  0x95184460, 0xdc4e7487, 0x156e0c29, 0x2413d5e3, 0x61c1696d, 0xd24aaebd, 0x473826fd, 0xa0c238b9,
507  0x0ab111bb, 0xbd67c724, 0x972cd18b, 0xfbbd9d42, 0x6c472096, 0xe76115c0, 0x5f6f7ceb, 0xac9f45ae,
508  0xcecb72f1, 0x9c38339d, 0x8f682625, 0x0dea891e, 0xf07afff3, 0xa892374e, 0x175eb4af, 0xc8daadd8,
509  0x85db6ab0, 0x3a49bd0d, 0xc0b1b31d, 0x8a0e23fa, 0xc5e5767d, 0xf95884e0, 0x6425a415, 0x26fac51c,
510  0x3ea8449f, 0xe8f70edd, 0x062b1a63, 0xa6c4c60c, 0x52ab3316, 0x1e238438, 0x897a39ce, 0x78b63c9f,
511  0x364f5b8a, 0xef22ec2f, 0xee6e0850, 0xeca42d06, 0xfb0c75df, 0x5497e00c, 0x554b03d7, 0xd2874a00,
512  0x0ca8f58d, 0x94f0341c, 0xbe2ec921, 0x56c9f949, 0xdb4a9316, 0xf281501e, 0x53daec3f, 0x64f1b783,
513  0x154c6032, 0x0e2ff793, 0x33ce3573, 0xfacc5fdc, 0xf1178590, 0x3155bbd9, 0x0f023b22, 0x0224fcd8,
514  0x471bf4f4, 0x45f0a88a, 0x14f0cd97, 0x6ea354bb, 0x20cdb5cc, 0xb3db2392, 0x88d58655, 0x4e2a0e8a,
515  0x6fe51a8c, 0xfaa72ef2, 0xad8a43dc, 0x4212b210, 0xb779dfe4, 0x9d7307cc, 0x846532e4, 0xb9694eda,
516  0xd162af05, 0x3b1751f3, 0xa3d091f6, 0x56658154, 0x12b5e8c2, 0x02461069, 0xac14b958, 0x784934b8,
517  0xd6cce1da, 0xa5053701, 0x1aa4fb42, 0xb9a3def4, 0x1bda1f85, 0xef6fdbf2, 0xf2d89d2a, 0x4b183527,
518  0x8fd94057, 0x89f45681, 0x2b552879, 0xa6168695, 0xc12963b0, 0xff01eaab, 0x73e5b5c1, 0x585318e7,
519  0x624f14a5, 0x1a4a026b, 0x68082920, 0x57fd99b6, 0x6dc085a9, 0x8ac8d8ca, 0xf9eeeea9, 0x8a2400ca,
520  0xc95f260f, 0xd10036f9, 0xf91096ac, 0x3195220a, 0x1a356b2a, 0x73b7eaad, 0xaf6d6058, 0x71ef7afb,
521  0x80bc4234, 0x33562e94, 0xb12dfab4, 0x14451579, 0xdf59eae0, 0x51707062, 0x4012a829, 0x62c59cab,
522  0x347f8304, 0xd889659e, 0x5a9139db, 0x14efcc30, 0x852be3e8, 0xfc99f14d, 0x1d822dd6, 0xe2f76797,
523  0xe30219c8, 0xaa9ce884, 0x8a886eb3, 0xc87b7295, 0x988012e8, 0x314186ed, 0xbaf86856, 0xccd3c3b6,
524  0xee94e62f, 0x110a6783, 0xd2aae89c, 0xcc3b76fc, 0x435a0ce1, 0x34c2838f, 0xd571ec6c, 0x1366a993 // last one was: 0x1366a992
525  //0xcbb9ac40, ...
526  // (the last word 0x1366a992 was rounded up because the next one is 0xcbb9ac40 -- first bit is one 0xc..)
527  // 256 32bit words for the mantissa -- about 2464 valid decimal digits
528  };
529 
530  // above value was calculated using Big<1,400> type on a 32bit platform
531  // and then the first 256 words were taken,
532  // the calculating was made by using LnSurrounding1(2) method
533  // which took 4035 iterations
534  // (the result was compared with ln(2) taken from http://ja0hxv.calico.jp/pai/estart.html)
535  // (TTMATH_BUILTIN_VARIABLES_SIZE on 32bit platform should have the value 256,
536  // and on 64bit platform value 128 (256/2=128))
537 
538  mantissa.SetFromTable(temp_table, sizeof(temp_table) / sizeof(int));
539  exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT);
540  info = 0;
541  }
void SetFromTable(const unsigned int *temp_table, uint temp_table_len)
Definition: ttmathuint.h:325
signed long sint
Definition: ttmathtypes.h:243
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253

§ SetMax()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetMax ( )

this method sets the maximum value which can be held in this type

Definition at line 618 of file ttmathbig.h.

References ttmath::Int< value_size >::SetMax(), and ttmath::UInt< value_size >::SetMax().

619  {
620  info = 0;
621  mantissa.SetMax();
622  exponent.SetMax();
623 
624  // we don't have to use 'Standardizing()' because the last bit from
625  // the mantissa is set
626  }
void SetMax()
Definition: ttmathuint.h:215
void SetMax()
Definition: ttmathint.h:71

§ SetMin()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetMin ( )

this method sets the minimum value which can be held in this type

Definition at line 632 of file ttmathbig.h.

References ttmath::Int< value_size >::SetMax(), ttmath::UInt< value_size >::SetMax(), and ttmath::Big< exp, man >::SetSign().

633  {
634  info = 0;
635 
636  mantissa.SetMax();
637  exponent.SetMax();
638  SetSign();
639 
640  // we don't have to use 'Standardizing()' because the last bit from
641  // the mantissa is set
642  }
void SetSign()
Definition: ttmathbig.h:726
void SetMax()
Definition: ttmathuint.h:215
void SetMax()
Definition: ttmathint.h:71

§ SetNan()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetNan ( )

§ SetOne()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetOne ( )

this method sets one

Definition at line 271 of file ttmathbig.h.

References ttmath::UInt< value_size >::SetZero(), ttmath::UInt< value_size >::table, TTMATH_BITS_PER_UINT, and TTMATH_UINT_HIGHEST_BIT.

Referenced by ttmath::Big< exp, man >::Exp(), ttmath::Big< exp, man >::Log(), ttmath::Big< exp, man >::Pow(), ttmath::Big< exp, man >::PowInt(), ttmath::Big< exp, man >::PowUInt(), ttmath::Big< exp, man >::Set05(), ttmath::Big< exp, man >::Sgn(), and ttmath::Big< exp, man >::Sqrt().

272  {
273  info = 0;
274  mantissa.SetZero();
275  mantissa.table[man-1] = TTMATH_UINT_HIGHEST_BIT;
276  exponent = -sint(man * TTMATH_BITS_PER_UINT - 1);
277 
278  // don't have to Standardize() - the last bit from mantissa is set
279  }
signed long sint
Definition: ttmathtypes.h:243
uint table[value_size]
Definition: ttmathuint.h:81
#define TTMATH_UINT_HIGHEST_BIT
Definition: ttmathtypes.h:258
void SetZero()
Definition: ttmathuint.h:188
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253

§ SetPi()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetPi ( )

this method sets the value of pi

Definition at line 393 of file ttmathbig.h.

References TTMATH_BITS_PER_UINT.

394  {
395  // IMPROVE ME
396  // give some compiler-time warning when the size of mantissa is greater than the builtin size of the mantissa pi
397  SetMantissaPi();
398  info = 0;
399  exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 2;
400  }
signed long sint
Definition: ttmathtypes.h:243
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253

§ SetSign()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetSign ( )

this method sets the sign

samples

  • -1 -> -1
  • 2 -> -2

we do not check whether there is a zero or not, if you're using this method you must be sure that the value is (or will be afterwards) different from zero

Definition at line 726 of file ttmathbig.h.

References ttmath::Big< exp, man >::SetInfoBit(), and TTMATH_BIG_SIGN.

Referenced by ttmath::Big< exp, man >::Big(), ttmath::Big< exp, man >::FromInt(), ttmath::Big< exp, man >::Mul(), ttmath::Big< exp, man >::MulInt(), ttmath::Big< exp, man >::SetMin(), and ttmath::Big< exp, man >::Sgn().

727  {
729  }
#define TTMATH_BIG_SIGN
Definition: ttmathbig.h:97
void SetInfoBit(unsigned char bit)
Definition: ttmathbig.h:236

§ SetZero()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetZero ( )

§ SetZeroNan()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SetZeroNan ( )

this method sets NaN flag (Not a Number) also clears the mantissa and exponent (similarly as it would be a zero value)

Definition at line 306 of file ttmathbig.h.

References ttmath::Big< exp, man >::SetNan(), and ttmath::Big< exp, man >::SetZero().

Referenced by ttmath::Big< exp, man >::Big().

307  {
308  SetZero();
309  SetNan();
310  }
void SetNan()
Definition: ttmathbig.h:296
void SetZero()
Definition: ttmathbig.h:256

§ Sgn()

template<uint exp, uint man>
void ttmath::Big< exp, man >::Sgn ( )

this method remains the 'sign' of the value

samples

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

Definition at line 696 of file ttmathbig.h.

References ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::SetOne(), ttmath::Big< exp, man >::SetSign(), and ttmath::Big< exp, man >::SetZero().

697  {
698  // we have to check the NaN flag, because the next SetOne() method would clear it
699  if( IsNan() )
700  return;
701 
702  if( IsSign() )
703  {
704  SetOne();
705  SetSign();
706  }
707  else
708  if( IsZero() )
709  SetZero(); // !! is nedeed here?
710  else
711  SetOne();
712  }
bool IsSign() const
Definition: ttmathbig.h:658
void SetSign()
Definition: ttmathbig.h:726
void SetOne()
Definition: ttmathbig.h:271
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
void SetZero()
Definition: ttmathbig.h:256

§ SkipFraction()

template<uint exp, uint man>
void ttmath::Big< exp, man >::SkipFraction ( )

this method makes an integer value by skipping any fractions

samples:

  • 10.7 will be 10
  • 12.1 – 12
  • -20.2 – 20
  • -20.9 – 20
  • -0.7 – 0
  • 0.8 – 0

Definition at line 5790 of file ttmathbig.h.

References ttmath::UInt< value_size >::ClearFirstBits(), ttmath::Big< exp, man >::IsNan(), ttmath::Int< value_size >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::SetZero(), and ttmath::Int< value_size >::ToInt().

Referenced by ttmath::Big< exp, man >::Div(), and ttmath::Big< exp, man >::Round().

5791  {
5792  if( IsNan() || IsZero() )
5793  return;
5794 
5795  if( !exponent.IsSign() )
5796  // exponent >=0 -- the value don't have any fractions
5797  return;
5798 
5799  if( exponent <= -sint(man*TTMATH_BITS_PER_UINT) )
5800  {
5801  // the value is from (-1,1), we return zero
5802  SetZero();
5803  return;
5804  }
5805 
5806  // exponent is in range (-man*TTMATH_BITS_PER_UINT, 0)
5807  sint e = exponent.ToInt();
5808 
5809  mantissa.ClearFirstBits( -e );
5810 
5811  // we don't have to standardize 'Standardizing()' the value because
5812  // there's at least one bit in the mantissa
5813  // (the highest bit which we didn't touch)
5814  }
signed long sint
Definition: ttmathtypes.h:243
bool IsZero() const
Definition: ttmathbig.h:648
bool IsSign() const
Definition: ttmathint.h:156
bool IsNan() const
Definition: ttmathbig.h:667
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
void ClearFirstBits(uint n)
Definition: ttmathuint.h:2508
void SetZero()
Definition: ttmathbig.h:256
sint ToInt() const
Definition: ttmathint.h:1132

§ SmallerWithoutSignThan()

template<uint exp, uint man>
bool ttmath::Big< exp, man >::SmallerWithoutSignThan ( const Big< exp, man > &  ss2) const

methods for comparing

this method performs the formula 'abs(this) < abs(ss2)' and returns the result

(in other words it treats 'this' and 'ss2' as values without a sign) we don't check the NaN flag

Definition at line 5401 of file ttmathbig.h.

References ttmath::Big< exp, man >::IsZero().

Referenced by ttmath::Big< exp, man >::Add(), ttmath::Big< exp, man >::BitAnd(), ttmath::Big< exp, man >::BitOr(), ttmath::Big< exp, man >::BitXor(), ttmath::Big< exp, man >::Div(), and ttmath::Big< exp, man >::EqualWithoutSign().

5402  {
5403  if( IsZero() )
5404  {
5405  if( ss2.IsZero() )
5406  // we've got two zeroes
5407  return false;
5408  else
5409  // this==0 and ss2!=0
5410  return true;
5411  }
5412 
5413  if( ss2.IsZero() )
5414  {
5415  // this!=0 and ss2==0
5416  return false;
5417  }
5418 
5419  // we're using the fact that all bits in mantissa are pushed
5420  // into the left side -- Standardizing()
5421  if( exponent == ss2.exponent )
5422  return mantissa < ss2.mantissa;
5423 
5424  return exponent < ss2.exponent;
5425  }
bool IsZero() const
Definition: ttmathbig.h:648

§ Sqrt()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Sqrt ( )

this function calculates the square root e.g. let this=9 then this.Sqrt() gives 3

return:

  • 0 - ok
  • 1 - carry
  • 2 - improper argument (this<0 or NaN)

Definition at line 1817 of file ttmathbig.h.

References ttmath::Big< exp, man >::Add(), ttmath::Big< exp, man >::CheckCarry(), ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::Exp(), ttmath::Big< exp, man >::IsInteger(), ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::Big< exp, man >::Ln(), ttmath::Big< exp, man >::Mul(), ttmath::Big< exp, man >::Round(), ttmath::Big< exp, man >::SetNan(), ttmath::Big< exp, man >::SetOne(), ttmath::Int< value_size >::SubOne(), TTMATH_ARITHMETIC_MAX_LOOP, and TTMATH_REFERENCE_ASSERT.

1818  {
1819  if( IsNan() || IsSign() )
1820  {
1821  SetNan();
1822  return 2;
1823  }
1824 
1825  if( IsZero() )
1826  return 0;
1827 
1828  Big<exp, man> old(*this);
1829  Big<exp, man> ln;
1830  uint c = 0;
1831 
1832  // we're using the formula: sqrt(x) = e ^ (ln(x) / 2)
1833  c += ln.Ln(*this);
1834  c += ln.exponent.SubOne(); // ln = ln / 2
1835  c += Exp(ln);
1836 
1837  // above formula doesn't give accurate results for some integers
1838  // e.g. Sqrt(81) would not be 9 but a value very closed to 9
1839  // we're rounding the result, calculating result*result and comparing
1840  // with the old value, if they are equal then the result is an integer too
1841 
1842  if( !c && old.IsInteger() && !IsInteger() )
1843  {
1844  Big<exp, man> temp(*this);
1845  c += temp.Round();
1846 
1847  Big<exp, man> temp2(temp);
1848  c += temp.Mul(temp2);
1849 
1850  if( temp == old )
1851  *this = temp2;
1852  }
1853 
1854  return CheckCarry(c);
1855  }
bool IsSign() const
Definition: ttmathbig.h:658
uint CheckCarry(uint c)
Definition: ttmathbig.h:121
void SetNan()
Definition: ttmathbig.h:296
uint Exp(const Big< exp, man > &x)
Definition: ttmathbig.h:1948
bool IsZero() const
Definition: ttmathbig.h:648
bool IsInteger() const
Definition: ttmathbig.h:5865
bool IsNan() const
Definition: ttmathbig.h:667
unsigned long uint
Definition: ttmathtypes.h:238

§ Standardizing()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Standardizing ( )

this method moves all bits from mantissa into its left side (suitably changes the exponent) or if the mantissa is zero it sets the exponent to zero as well (and clears the sign bit and sets the zero bit)

it can return a carry the carry will be when we don't have enough space in the exponent

you don't have to use this method if you don't change the mantissa and exponent directly

Definition at line 173 of file ttmathbig.h.

References ttmath::Big< exp, man >::ClearInfoBit(), ttmath::UInt< value_size >::CompensationToLeft(), ttmath::UInt< value_size >::IsTheHighestBitSet(), ttmath::UInt< value_size >::IsZero(), ttmath::Big< exp, man >::SetInfoBit(), ttmath::UInt< value_size >::SetZero(), ttmath::Int< value_size >::Sub(), TTMATH_BIG_SIGN, and TTMATH_BIG_ZERO.

Referenced by ttmath::Big< exp, man >::Add(), ttmath::Big< exp, man >::Big(), ttmath::Big< exp, man >::BitAnd(), ttmath::Big< exp, man >::BitOr(), ttmath::Big< exp, man >::BitXor(), ttmath::Big< exp, man >::FromDouble(), ttmath::Big< exp, man >::FromUInt(), ttmath::Big< exp, man >::Mul(), ttmath::Big< exp, man >::MulUInt(), and ttmath::Big< exp, man >::RemainFraction().

174  {
175  if( mantissa.IsTheHighestBitSet() )
176  {
178  return 0;
179  }
180 
181  if( CorrectZero() )
182  return 0;
183 
184  uint comp = mantissa.CompensationToLeft();
185 
186  return exponent.Sub( comp );
187  }
void ClearInfoBit(unsigned char bit)
Definition: ttmathbig.h:224
bool IsTheHighestBitSet() const
Definition: ttmathuint.h:2547
#define TTMATH_BIG_ZERO
Definition: ttmathbig.h:113
uint CompensationToLeft()
Definition: ttmathuint.h:598
unsigned long uint
Definition: ttmathtypes.h:238
uint Sub(const Int< value_size > &ss2)
Definition: ttmathint.h:299

§ Sub()

template<uint exp, uint man>
uint ttmath::Big< exp, man >::Sub ( const Big< exp, man > &  ss2,
bool  round = true 
)

Subtraction this = this - ss2

it returns carry if the result is too big

Definition at line 978 of file ttmathbig.h.

References ttmath::Big< exp, man >::Add().

Referenced by ttmath::Big< exp, man >::Div(), ttmath::Big< exp, man >::Exp(), ttmath::Big< exp, man >::operator-(), and ttmath::Big< exp, man >::Round().

979  {
980  return Add(ss2, round, false);
981  }
uint Add(Big< exp, man > ss2, bool round=true, bool adding=true)
Definition: ttmathbig.h:930

§ Swap()

template<uint exp, uint man>
void ttmath::Big< exp, man >::Swap ( Big< exp, man > &  ss2)

this method swappes this for an argument

Definition at line 316 of file ttmathbig.h.

References ttmath::UInt< value_size >::SetFromTable(), and ttmath::UInt< value_size >::Swap().

Referenced by ttmath::Big< exp, man >::Add(), ttmath::Big< exp, man >::BitAnd(), ttmath::Big< exp, man >::BitOr(), and ttmath::Big< exp, man >::BitXor().

317  {
318  unsigned char info_temp = info;
319  info = ss2.info;
320  ss2.info = info_temp;
321 
322  exponent.Swap(ss2.exponent);
323  mantissa.Swap(ss2.mantissa);
324  }
void Swap(UInt< value_size > &ss2)
Definition: ttmathuint.h:239

§ ToDouble() [1/2]

template<uint exp, uint man>
double ttmath::Big< exp, man >::ToDouble ( ) const

this method converts from this class into the 'double'

if the value is too big: 'result' will be +/-infinity (depending on the sign)

if the value is too small: 'result' will be 0

Definition at line 2830 of file ttmathbig.h.

Referenced by ttmath::Big< exp, man >::ToFloat().

2831  {
2832  double result;
2833 
2834  ToDouble(result);
2835 
2836  return result;
2837  }
double ToDouble() const
Definition: ttmathbig.h:2830

§ ToDouble() [2/2]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToDouble ( double &  result) const

this method converts from this class into the 'double'

if the value is too big:

  • 'result' will be +/-infinity (depending on the sign)
  • and the method returns 1

if the value is too small:

  • 'result' will be 0
  • and the method returns 1

Definition at line 2961 of file ttmathbig.h.

References ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::Rcr(), ttmath::UInt< value_size >::table, ttmath::Int< value_size >::ToInt(), and TTMATH_BITS_PER_UINT.

2962  {
2963  if( IsZero() )
2964  {
2965  result = 0.0;
2966  return 0;
2967  }
2968 
2969  if( IsNan() )
2970  {
2971  result = ToDouble_SetDouble( false, 2047, 0, false, true);
2972 
2973  return 0;
2974  }
2975 
2976  sint e_correction = sint(man*TTMATH_BITS_PER_UINT) - 1;
2977 
2978  if( exponent >= 1024 - e_correction )
2979  {
2980  // +/- infinity
2981  result = ToDouble_SetDouble( IsSign(), 2047, 0, true);
2982 
2983  return 1;
2984  }
2985  else
2986  if( exponent <= -1023 - 52 - e_correction )
2987  {
2988  // too small value - we assume that there'll be a zero
2989  result = 0;
2990 
2991  // and return a carry
2992  return 1;
2993  }
2994 
2995  sint e = exponent.ToInt() + e_correction;
2996 
2997  if( e <= -1023 )
2998  {
2999  // -1023-52 < e <= -1023 (unnormalized value)
3000  result = ToDouble_SetDouble( IsSign(), 0, -(e + 1023));
3001  }
3002  else
3003  {
3004  // -1023 < e < 1024
3005  result = ToDouble_SetDouble( IsSign(), e + 1023, -1);
3006  }
3007 
3008  return 0;
3009  }
signed long sint
Definition: ttmathtypes.h:243
bool IsSign() const
Definition: ttmathbig.h:658
bool IsZero() const
Definition: ttmathbig.h:648
bool IsNan() const
Definition: ttmathbig.h:667
#define TTMATH_BITS_PER_UINT
Definition: ttmathtypes.h:253
sint ToInt() const
Definition: ttmathint.h:1132

§ ToFloat() [1/2]

template<uint exp, uint man>
float ttmath::Big< exp, man >::ToFloat ( ) const

this method converts from this class into the 'float'

if the value is too big: 'result' will be +/-infinity (depending on the sign)

if the value is too small: 'result' will be 0

Definition at line 2902 of file ttmathbig.h.

2903  {
2904  float result;
2905 
2906  ToFloat(result);
2907 
2908  return result;
2909  }
float ToFloat() const
Definition: ttmathbig.h:2902

§ ToFloat() [2/2]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToFloat ( float &  result) const

this method converts from this class into the 'float'

if the value is too big:

  • 'result' will be +/-infinity (depending on the sign)
  • and the method returns 1

if the value is too small:

  • 'result' will be 0
  • and the method returns 1

Definition at line 2923 of file ttmathbig.h.

References ttmath::Big< exp, man >::ToDouble().

2924  {
2925  double result_double;
2926 
2927  uint c = ToDouble(result_double);
2928  result = float(result_double);
2929 
2930  if( result == -0.0f )
2931  result = 0.0f;
2932 
2933  if( c )
2934  return 1;
2935 
2936  // although the result_double can have a correct value
2937  // but after converting to float there can be infinity
2938 
2939  if( IsInf(result) )
2940  return 1;
2941 
2942  if( result == 0.0f && result_double != 0.0 )
2943  // result_double was too small for float
2944  return 1;
2945 
2946  return 0;
2947  }
double ToDouble() const
Definition: ttmathbig.h:2830
unsigned long uint
Definition: ttmathtypes.h:238

§ ToInt() [1/7]

template<uint exp, uint man>
sint ttmath::Big< exp, man >::ToInt ( ) const

this method converts 'this' into sint

Definition at line 2348 of file ttmathbig.h.

Referenced by ttmath::Big< exp, man >::Big(), and ttmath::Big< exp, man >::ToInt().

2349  {
2350  sint result;
2351 
2352  ToInt(result);
2353 
2354  return result;
2355  }
signed long sint
Definition: ttmathtypes.h:243
sint ToInt() const
Definition: ttmathbig.h:2348

§ ToInt() [2/7]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToInt ( uint result) const

this method converts 'this' into 'result'

if the value is too big this method returns a carry (1)

Definition at line 2363 of file ttmathbig.h.

References ttmath::Big< exp, man >::ToUInt().

2364  {
2365  return ToUInt(result);
2366  }
uint ToUInt() const
Definition: ttmathbig.h:2318

§ ToInt() [3/7]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToInt ( sint result) const

this method converts 'this' into 'result'

if the value is too big this method returns a carry (1)

Definition at line 2374 of file ttmathbig.h.

References ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), ttmath::UInt< value_size >::Rcl(), ttmath::UInt< value_size >::Rcr(), ttmath::UInt< value_size >::SetZero(), ttmath::UInt< value_size >::table, ttmath::Int< value_size >::ToInt(), TTMATH_BITS_PER_UINT, TTMATH_UINT_HIGHEST_BIT, and TTMATH_UINT_MAX_VALUE.

2375  {
2376  uint result_uint;
2377 
2378  uint c = ToUIntOrInt(result_uint);
2379  result = sint(result_uint);
2380 
2381  if( c )
2382  return 1;
2383 
2384  uint mask = 0;
2385 
2386  if( IsSign() )
2387  {
2388  mask = TTMATH_UINT_MAX_VALUE;
2389  result = -result;
2390  }
2391 
2392  return ((result & TTMATH_UINT_HIGHEST_BIT) == (mask & TTMATH_UINT_HIGHEST_BIT)) ? 0 : 1;
2393  }
signed long sint
Definition: ttmathtypes.h:243
bool IsSign() const
Definition: ttmathbig.h:658
#define TTMATH_UINT_HIGHEST_BIT
Definition: ttmathtypes.h:258
#define TTMATH_UINT_MAX_VALUE
Definition: ttmathtypes.h:264
unsigned long uint
Definition: ttmathtypes.h:238

§ ToInt() [4/7]

template<uint exp, uint man>
template<uint int_size>
uint ttmath::Big< exp, man >::ToInt ( UInt< int_size > &  result) const

this method converts 'this' into 'result'

if the value is too big this method returns a carry (1)

Definition at line 2486 of file ttmathbig.h.

References ttmath::Big< exp, man >::ToUInt().

2487  {
2488  return ToUInt(result);
2489  }
uint ToUInt() const
Definition: ttmathbig.h:2318

§ ToInt() [5/7]

template<uint exp, uint man>
template<uint int_size>
uint ttmath::Big< exp, man >::ToInt ( Int< int_size > &  result) const

this method converts 'this' into 'result'

if the value is too big this method returns a carry (1)

Definition at line 2498 of file ttmathbig.h.

References ttmath::Int< value_size >::ChangeSign(), ttmath::Big< exp, man >::IsSign(), ttmath::UInt< value_size >::table, TTMATH_UINT_HIGHEST_BIT, and TTMATH_UINT_MAX_VALUE.

2499  {
2500  uint c = ToUIntOrInt(result);
2501 
2502  if( c )
2503  return 1;
2504 
2505  uint mask = 0;
2506 
2507  if( IsSign() )
2508  {
2509  result.ChangeSign();
2510  mask = TTMATH_UINT_MAX_VALUE;
2511  }
2512 
2513  return ((result.table[int_size-1] & TTMATH_UINT_HIGHEST_BIT) == (mask & TTMATH_UINT_HIGHEST_BIT))? 0 : 1;
2514  }
bool IsSign() const
Definition: ttmathbig.h:658
#define TTMATH_UINT_HIGHEST_BIT
Definition: ttmathtypes.h:258
#define TTMATH_UINT_MAX_VALUE
Definition: ttmathtypes.h:264
unsigned long uint
Definition: ttmathtypes.h:238

§ ToInt() [6/7]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToInt ( unsigned int &  result) const

this method converts 'this' into 'result' (32 bit unsigned integer) this method is created only on a 64bit platform*** if the value is too big this method returns a carry (1)

Definition at line 3381 of file ttmathbig.h.

References ttmath::Big< exp, man >::ToUInt().

3382  {
3383  return ToUInt(result);
3384  }
uint ToUInt() const
Definition: ttmathbig.h:2318

§ ToInt() [7/7]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToInt ( signed int &  result) const

this method converts 'this' into 'result' (32 bit signed integer) this method is created only on a 64bit platform*** if the value is too big this method returns a carry (1)

Definition at line 3392 of file ttmathbig.h.

References ttmath::Big< exp, man >::FromInt(), ttmath::Big< exp, man >::FromUInt(), and ttmath::Big< exp, man >::ToInt().

3393  {
3394  sint result_sint;
3395 
3396  uint c = ToInt(result_sint);
3397  result = (signed int)result_sint;
3398 
3399  if( c || result_sint != sint(result) )
3400  return 1;
3401 
3402  return 0;
3403  }
signed long sint
Definition: ttmathtypes.h:243
sint ToInt() const
Definition: ttmathbig.h:2348
unsigned long uint
Definition: ttmathtypes.h:238

§ ToString() [1/6]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToString ( std::string &  result,
uint  base = 10,
bool  scient = false,
sint  scient_from = 15,
sint  round = -1,
bool  trim_zeroes = true,
char  comma = '.' 
) const

a method for converting into a string struct Conv is defined in ttmathtypes.h, look there for more information about parameters

return value:

  • 0 - ok and 'result' will be an object of type std::string (or std::wstring) which holds the value
  • 1 - if there is a carry (it shoudn't be in a normal situation - if it is that means there is somewhere an error in the library)

Definition at line 3697 of file ttmathbig.h.

References ttmath::Conv::base, ttmath::Conv::comma, ttmath::Conv::round, ttmath::Conv::scient, ttmath::Conv::scient_from, and ttmath::Conv::trim_zeroes.

Referenced by ttmath::Big< exp, man >::Round(), and ttmath::Big< exp, man >::ToString().

3704  {
3705  Conv conv;
3706 
3707  conv.base = base;
3708  conv.scient = scient;
3709  conv.scient_from = scient_from;
3710  conv.round = round;
3711  conv.trim_zeroes = trim_zeroes;
3712  conv.comma = static_cast<uint>(comma);
3713 
3714  return ToStringBase<std::string, char>(result, conv);
3715  }
unsigned long uint
Definition: ttmathtypes.h:238

§ ToString() [2/6]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToString ( std::string &  result,
const Conv conv 
) const

a method for converting into a string struct Conv is defined in ttmathtypes.h, look there for more information about parameters

Definition at line 3722 of file ttmathbig.h.

3723  {
3724  return ToStringBase<std::string, char>(result, conv);
3725  }

§ ToString() [3/6]

template<uint exp, uint man>
std::string ttmath::Big< exp, man >::ToString ( const Conv conv) const

a method for converting into a string struct Conv is defined in ttmathtypes.h, look there for more information about parameters

Definition at line 3732 of file ttmathbig.h.

3733  {
3734  std::string result;
3735  ToStringBase<std::string, char>(result, conv);
3736 
3737  return result;
3738  }

§ ToString() [4/6]

template<uint exp, uint man>
std::string ttmath::Big< exp, man >::ToString ( uint  base = 10) const

a method for converting into a string struct Conv is defined in ttmathtypes.h, look there for more information about parameters

Definition at line 3745 of file ttmathbig.h.

References ttmath::Conv::base, and ttmath::Big< exp, man >::ToString().

3746  {
3747  Conv conv;
3748  conv.base = base;
3749 
3750  return ToString(conv);
3751  }
uint ToString(std::string &result, uint base=10, bool scient=false, sint scient_from=15, sint round=-1, bool trim_zeroes=true, char comma='.') const
Definition: ttmathbig.h:3697

§ ToString() [5/6]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToString ( std::wstring &  result,
uint  base = 10,
bool  scient = false,
sint  scient_from = 15,
sint  round = -1,
bool  trim_zeroes = true,
wchar_t  comma = '.' 
) const

a method for converting into a string struct Conv is defined in ttmathtypes.h, look there for more information about parameters

Definition at line 3762 of file ttmathbig.h.

References ttmath::Conv::base, ttmath::Conv::comma, ttmath::Conv::round, ttmath::Conv::scient, ttmath::Conv::scient_from, and ttmath::Conv::trim_zeroes.

3769  {
3770  Conv conv;
3771 
3772  conv.base = base;
3773  conv.scient = scient;
3774  conv.scient_from = scient_from;
3775  conv.round = round;
3776  conv.trim_zeroes = trim_zeroes;
3777  conv.comma = static_cast<uint>(comma);
3778 
3779  return ToStringBase<std::wstring, wchar_t>(result, conv);
3780  }
unsigned long uint
Definition: ttmathtypes.h:238

§ ToString() [6/6]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToString ( std::wstring &  result,
const Conv conv 
) const

a method for converting into a string struct Conv is defined in ttmathtypes.h, look there for more information about parameters

Definition at line 3787 of file ttmathbig.h.

3788  {
3789  return ToStringBase<std::wstring, wchar_t>(result, conv);
3790  }

§ ToUInt() [1/4]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToUInt ( ) const

this method converts 'this' into uint

Definition at line 2318 of file ttmathbig.h.

Referenced by ttmath::Big< exp, man >::Big(), ttmath::Big< exp, man >::ToInt(), and ttmath::Big< exp, man >::ToUInt().

2319  {
2320  uint result;
2321 
2322  ToUInt(result);
2323 
2324  return result;
2325  }
uint ToUInt() const
Definition: ttmathbig.h:2318
unsigned long uint
Definition: ttmathtypes.h:238

§ ToUInt() [2/4]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToUInt ( uint result) const

this method converts 'this' into 'result'

if the value is too big this method returns a carry (1)

Definition at line 2333 of file ttmathbig.h.

References ttmath::Big< exp, man >::IsSign().

2334  {
2335  if( ToUIntOrInt(result) )
2336  return 1;
2337 
2338  if( IsSign() )
2339  return 1;
2340 
2341  return 0;
2342  }
bool IsSign() const
Definition: ttmathbig.h:658

§ ToUInt() [3/4]

template<uint exp, uint man>
template<uint int_size>
uint ttmath::Big< exp, man >::ToUInt ( UInt< int_size > &  result) const

this method converts 'this' into 'result'

if the value is too big this method returns a carry (1)

Definition at line 2466 of file ttmathbig.h.

References ttmath::Big< exp, man >::IsSign().

2467  {
2468  uint c = ToUIntOrInt(result);
2469 
2470  if( c )
2471  return 1;
2472 
2473  if( IsSign() )
2474  return 1;
2475 
2476  return 0;
2477  }
bool IsSign() const
Definition: ttmathbig.h:658
unsigned long uint
Definition: ttmathtypes.h:238

§ ToUInt() [4/4]

template<uint exp, uint man>
uint ttmath::Big< exp, man >::ToUInt ( unsigned int &  result) const

this method converts 'this' into 'result' (32 bit unsigned integer) this method is created only on a 64bit platform*** if the value is too big this method returns a carry (1)

Definition at line 3362 of file ttmathbig.h.

References ttmath::Big< exp, man >::ToUInt().

3363  {
3364  uint result_uint;
3365 
3366  uint c = ToUInt(result_uint);
3367  result = (unsigned int)result_uint;
3368 
3369  if( c || result_uint != uint(result) )
3370  return 1;
3371 
3372  return 0;
3373  }
uint ToUInt() const
Definition: ttmathbig.h:2318
unsigned long uint
Definition: ttmathtypes.h:238

§ ToWString() [1/2]

template<uint exp, uint man>
std::wstring ttmath::Big< exp, man >::ToWString ( const Conv conv) const

a method for converting into a string struct Conv is defined in ttmathtypes.h, look there for more information about parameters

Definition at line 3797 of file ttmathbig.h.

Referenced by ttmath::Big< exp, man >::ToWString().

3798  {
3799  std::wstring result;
3800  ToStringBase<std::wstring, wchar_t>(result, conv);
3801 
3802  return result;
3803  }

§ ToWString() [2/2]

template<uint exp, uint man>
std::wstring ttmath::Big< exp, man >::ToWString ( uint  base = 10) const

a method for converting into a string struct Conv is defined in ttmathtypes.h, look there for more information about parameters

Definition at line 3810 of file ttmathbig.h.

References ttmath::Misc::AssignString(), ttmath::Conv::base, ttmath::Big< exp, man >::IsNan(), ttmath::Big< exp, man >::IsSign(), ttmath::Big< exp, man >::IsZero(), and ttmath::Big< exp, man >::ToWString().

3811  {
3812  Conv conv;
3813  conv.base = base;
3814 
3815  return ToWString(conv);
3816  }
std::wstring ToWString(const Conv &conv) const
Definition: ttmathbig.h:3797

Friends And Related Function Documentation

§ Big< exp-1, man >

template<uint exp, uint man>
friend class Big< exp-1, man >
friend

in the method 'ToString_CreateNewMantissaAndExponent()' we're using type 'Big<exp+1,man>' and we should have the ability to use some necessary methods from that class (methods which are private here)

Definition at line 3899 of file ttmathbig.h.

§ operator<< [1/2]

template<uint exp, uint man>
std::ostream& operator<< ( std::ostream &  s,
const Big< exp, man > &  l 
)
friend

output to standard streams

Definition at line 5971 of file ttmathbig.h.

5972  {
5973  return OutputToStream<std::ostream, std::string>(s, l);
5974  }

§ operator<< [2/2]

template<uint exp, uint man>
std::wostream& operator<< ( std::wostream &  s,
const Big< exp, man > &  l 
)
friend

output to standard streams

Definition at line 5982 of file ttmathbig.h.

5983  {
5984  return OutputToStream<std::wostream, std::wstring>(s, l);
5985  }

§ operator>> [1/2]

template<uint exp, uint man>
std::istream& operator>> ( std::istream &  s,
Big< exp, man > &  l 
)
friend

input from standard streams

Definition at line 6070 of file ttmathbig.h.

6071  {
6072  return InputFromStream<std::istream, std::string, char>(s, l);
6073  }

§ operator>> [2/2]

template<uint exp, uint man>
std::wistream& operator>> ( std::wistream &  s,
Big< exp, man > &  l 
)
friend

input from standard streams

Definition at line 6081 of file ttmathbig.h.

6082  {
6083  return InputFromStream<std::wistream, std::wstring, wchar_t>(s, l);
6084  }

The documentation for this class was generated from the following file: