Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: PIDHeater82 Conceptcontroller_v_1_0 AlarmClockApp COG4050_adxl355_tilt ... more
Int< value_size > Class Template Reference
Int implements a big integer value with a sign. More...
#include <ttmathint.h>
Inherits ttmath::UInt< value_size >.
Public Member Functions | |
| void | SetMax () |
| void | SetMin () |
| void | SetSignOne () |
| uint | ChangeSign () |
| void | SetSign () |
| bool | IsSign () const |
| uint | Abs () |
| uint | Add (const Int< value_size > &ss2) |
| uint | AddInt (uint value, uint index=0) |
| uint | AddTwoInts (uint x2, uint x1, uint index) |
| uint | Sub (const Int< value_size > &ss2) |
| uint | SubInt (uint value, uint index=0) |
| uint | AddOne () |
| uint | SubOne () |
| uint | MulInt (sint ss2) |
| uint | Mul (Int< value_size > ss2) |
| uint | Div (Int< value_size > ss2, Int< value_size > *remainder=0) |
| uint | DivInt (sint ss2, sint *remainder=0) |
| uint | Pow (Int< value_size > pow) |
| template<uint argument_size> | |
| uint | FromInt (const Int< argument_size > &p) |
| uint | FromInt (sint value) |
| template<uint argument_size> | |
| uint | FromUInt (const UInt< argument_size > &p) |
| template<uint argument_size> | |
| uint | FromInt (const UInt< argument_size > &p) |
| uint | FromUInt (uint value) |
| uint | FromInt (uint value) |
| Int< value_size > & | operator= (const Int< value_size > &p) |
| template<uint argument_size> | |
| Int< value_size > & | operator= (const Int< argument_size > &p) |
| Int< value_size > & | operator= (sint i) |
| Int (sint i) | |
| Int (const Int< value_size > &u) | |
| template<uint argument_size> | |
| Int (const Int< argument_size > &u) | |
| template<uint argument_size> | |
| Int< value_size > & | operator= (const UInt< argument_size > &p) |
| Int< value_size > & | operator= (uint i) |
| Int (uint i) | |
| template<uint argument_size> | |
| Int (const UInt< argument_size > &u) | |
| uint | FromUInt (ulint n) |
| uint | FromInt (ulint n) |
| uint | FromInt (slint n) |
| Int< value_size > & | operator= (ulint n) |
| Int (ulint n) | |
| Int< value_size > & | operator= (slint n) |
| Int (slint n) | |
| uint | FromUInt (unsigned int i) |
| uint | FromInt (unsigned int i) |
| uint | FromInt (signed int i) |
| Int< value_size > & | operator= (unsigned int i) |
| Int (unsigned int i) | |
| Int< value_size > & | operator= (signed int i) |
| Int (signed int i) | |
| Int (const char *s) | |
| Int (const std::string &s) | |
| Int (const wchar_t *s) | |
| Int (const std::wstring &s) | |
| Int () | |
| ~Int () | |
| sint | ToInt () const |
| uint | ToUInt (uint &result) const |
| uint | ToInt (uint &result) const |
| uint | ToInt (sint &result) const |
| uint | ToUInt (ulint &result) const |
| uint | ToInt (ulint &result) const |
| uint | ToInt (slint &result) const |
| uint | ToUInt (unsigned int &result) const |
| uint | ToInt (unsigned int &result) const |
| uint | ToInt (int &result) const |
| void | ToString (std::string &result, uint b=10) const |
| std::string | ToString (uint b=10) const |
| void | ToString (std::wstring &result, uint b=10) const |
| std::wstring | ToWString (uint b=10) const |
| uint | FromString (const char *s, uint b=10, const char **after_source=0, bool *value_read=0) |
| uint | FromString (const wchar_t *s, uint b=10, const wchar_t **after_source=0, bool *value_read=0) |
| uint | FromString (const std::string &s, uint b=10) |
| Int< value_size > & | operator= (const char *s) |
| uint | FromString (const std::wstring &s, uint b=10) |
| Int< value_size > & | operator= (const wchar_t *s) |
| Int< value_size > & | operator= (const std::wstring &s) |
| Int< value_size > & | operator= (const std::string &s) |
| bool | operator== (const Int< value_size > &l) const |
| Int< value_size > | operator- () const |
| UInt< value_size > & | operator++ () |
| UInt< value_size > | operator++ (int) |
| template<class ostream_type > | |
| void | PrintTable (ostream_type &output) const |
| template<class char_type , class ostream_type > | |
| void | PrintLog (const char_type *msg, ostream_type &output) const |
| template<class char_type , class ostream_type > | |
| void | PrintLog (const char_type *msg, uint carry, ostream_type &output) const |
| uint | Size () const |
| void | SetZero () |
| void | SetOne () |
| void | Swap (UInt< value_size > &ss2) |
| void | SetFromTable (const uint *temp_table, uint temp_table_len) |
| void | SetFromTable (const unsigned int *temp_table, uint temp_table_len) |
| uint | Rcl (uint bits, uint c=0) |
| uint | Rcr (uint bits, uint c=0) |
| uint | CompensationToLeft () |
| bool | FindLeadingBit (uint &table_id, uint &index) const |
| bool | FindLowestBit (uint &table_id, uint &index) const |
| uint | GetBit (uint bit_index) const |
| uint | SetBit (uint bit_index) |
| void | BitAnd (const UInt< value_size > &ss2) |
| void | BitOr (const UInt< value_size > &ss2) |
| void | BitXor (const UInt< value_size > &ss2) |
| void | BitNot () |
| void | BitNot2 () |
| uint | MulInt (uint ss2) |
| template<uint result_size> | |
| void | MulInt (uint ss2, UInt< result_size > &result) const |
| uint | Mul (const UInt< value_size > &ss2, uint algorithm=100) |
| void | MulBig (const UInt< value_size > &ss2, UInt< value_size *2 > &result, uint algorithm=100) |
| uint | Mul1 (const UInt< value_size > &ss2) |
| void | Mul1Big (const UInt< value_size > &ss2_, UInt< value_size *2 > &result) |
| uint | Mul2 (const UInt< value_size > &ss2) |
| void | Mul2Big (const UInt< value_size > &ss2, UInt< value_size *2 > &result) |
| uint | Mul3 (const UInt< value_size > &ss2) |
| void | Mul3Big (const UInt< value_size > &ss2, UInt< value_size *2 > &result) |
| uint | MulFastest (const UInt< value_size > &ss2) |
| void | MulFastestBig (const UInt< value_size > &ss2, UInt< value_size *2 > &result) |
| uint | DivInt (uint divisor, uint *remainder=0) |
| uint | Div (const UInt< value_size > &divisor, UInt< value_size > *remainder=0, uint algorithm=3) |
| uint | Div1 (const UInt< value_size > &divisor, UInt< value_size > *remainder=0) |
| uint | Div1 (const UInt< value_size > &divisor, UInt< value_size > &remainder) |
| uint | Div2 (const UInt< value_size > &divisor, UInt< value_size > *remainder=0) |
| uint | Div2 (const UInt< value_size > &divisor, UInt< value_size > &remainder) |
| uint | Div3 (const UInt< value_size > &ss2, UInt< value_size > *remainder=0) |
| uint | Div3 (const UInt< value_size > &ss2, UInt< value_size > &remainder) |
| uint | Pow (UInt< value_size > pow) |
| void | Sqrt () |
| void | ClearFirstBits (uint n) |
| bool | IsTheHighestBitSet () const |
| bool | IsTheLowestBitSet () const |
| bool | IsOnlyTheHighestBitSet () const |
| bool | IsOnlyTheLowestBitSet () const |
| bool | IsZero () const |
| bool | AreFirstBitsZero (uint bits) const |
| uint | ToUInt () const |
| template<class string_type > | |
| void | ToStringBase (string_type &result, uint b=10, bool negative=false) const |
| bool | CmpSmaller (const UInt< value_size > &l, sint index=-1) const |
| bool | CmpBigger (const UInt< value_size > &l, sint index=-1) const |
| bool | CmpEqual (const UInt< value_size > &l, sint index=-1) const |
| bool | CmpSmallerEqual (const UInt< value_size > &l, sint index=-1) const |
| bool | CmpBiggerEqual (const UInt< value_size > &l, sint index=-1) const |
| UInt< value_size > | operator- (const UInt< value_size > &p2) const |
| UInt< value_size > | operator~ () const |
| uint | Add (const UInt< value_size > &ss2, uint c=0) |
| uint | Sub (const UInt< value_size > &ss2, uint c=0) |
Static Public Member Functions | |
| template<class char_type , class ostream_type > | |
| static void | PrintVectorLog (const char_type *msg, ostream_type &output, const uint *vector, uint vector_len) |
| template<class char_type , class ostream_type > | |
| static void | PrintVectorLog (const char_type *msg, uint carry, ostream_type &output, const uint *vector, uint vector_len) |
| static uint | AddTwoWords (uint a, uint b, uint carry, uint *result) |
| static uint | SubTwoWords (uint a, uint b, uint carry, uint *result) |
| static void | DivTwoWords2 (uint a, uint b, uint c, uint *r, uint *rest) |
| static const char * | LibTypeStr () |
| static LibTypeCode | LibType () |
| static uint | AddVector (const uint *ss1, const uint *ss2, uint ss1_size, uint ss2_size, uint *result) |
| static uint | SubVector (const uint *ss1, const uint *ss2, uint ss1_size, uint ss2_size, uint *result) |
| static sint | FindLeadingBitInWord (uint x) |
| static sint | FindLowestBitInWord (uint x) |
| static uint | SetBitInWord (uint &value, uint bit) |
| static void | MulTwoWords (uint a, uint b, uint *result_high, uint *result_low) |
| static void | DivTwoWords (uint a, uint b, uint c, uint *r, uint *rest) |
Data Fields | |
| uint | table [value_size] |
Protected Member Functions | |
| double | ToStringLog2 (uint x) const |
Friends | |
| std::ostream & | operator<< (std::ostream &s, const Int< value_size > &l) |
| std::wostream & | operator<< (std::wostream &s, const Int< value_size > &l) |
| std::istream & | operator>> (std::istream &s, Int< value_size > &l) |
| std::wistream & | operator>> (std::wistream &s, Int< value_size > &l) |
| std::istream & | operator>> (std::istream &s, UInt< value_size > &l) |
| std::wistream & | operator>> (std::wistream &s, UInt< value_size > &l) |
| std::ostream & | operator<< (std::ostream &s, const UInt< value_size > &l) |
| std::wostream & | operator<< (std::wostream &s, const UInt< value_size > &l) |
Detailed Description
template<uint value_size>
class ttmath::Int< value_size >
Int implements a big integer value with a sign.
value_size - how many bytes specify our value on 32bit platforms: value_size=1 -> 4 bytes -> 32 bits on 64bit platforms: value_size=1 -> 8 bytes -> 64 bits value_size = 1,2,3,4,5,6....
Definition at line 63 of file ttmathint.h.
Constructor & Destructor Documentation
| Int | ( | sint | i ) |
a constructor for converting the uint to this class
Definition at line 806 of file ttmathint.h.
a copy constructor
Definition at line 815 of file ttmathint.h.
a constructor for copying from another types
Definition at line 825 of file ttmathint.h.
a constructor for converting the uint to this class
Definition at line 861 of file ttmathint.h.
a constructor for copying from another types
Definition at line 871 of file ttmathint.h.
a constructor for converting unsigned 64 bit int to this class this constructor is created only on a 32bit platform***
Definition at line 956 of file ttmathint.h.
| Int | ( | slint | n ) |
a constructor for converting signed 64 bit int to this class this constructor is created only on a 32bit platform***
Definition at line 978 of file ttmathint.h.
| Int | ( | unsigned int | i ) |
a constructor for converting 32 bit unsigned int to this class this constructor is created only on a 64bit platform***
Definition at line 1036 of file ttmathint.h.
| Int | ( | signed int | i ) |
a constructor for converting 32 bit signed int to this class this constructor is created only on a 64bit platform***
Definition at line 1058 of file ttmathint.h.
| Int | ( | const char * | s ) |
a constructor for converting string to this class (with the base=10)
Definition at line 1070 of file ttmathint.h.
| Int | ( | const std::string & | s ) |
a constructor for converting a string to this class (with the base=10)
Definition at line 1079 of file ttmathint.h.
| Int | ( | const wchar_t * | s ) |
a constructor for converting string to this class (with the base=10)
Definition at line 1090 of file ttmathint.h.
| Int | ( | const std::wstring & | s ) |
a constructor for converting a string to this class (with the base=10)
Definition at line 1099 of file ttmathint.h.
| Int | ( | ) |
| ~Int | ( | ) |
the destructor
Definition at line 1120 of file ttmathint.h.
Member Function Documentation
| uint Abs | ( | ) |
it sets an absolute value
it can return carry (1) (look on ChangeSign() for details)
Definition at line 167 of file ttmathint.h.
this method adds two value with a sign and returns a carry
we're using methods from the base class because values are stored with U2 we must only make the carry correction
this = p1(=this) + p2
when p1>=0 i p2>=0 carry is set when the highest bit of value is set when p1<0 i p2<0 carry is set when the highest bit of value is clear when p1>=0 i p2<0 carry will never be set when p1<0 i p2>=0 carry will never be set
Definition at line 219 of file ttmathint.h.
this method adding ss2 to the this and adding carry if it's defined (this = this + ss2 + c)
c must be zero or one (might be a bigger value than 1) function returns carry (1) (if it was)
basic mathematic functions
adding ss2 to the this and adding carry if it's defined (this = this + ss2 + c)
c must be zero or one (might be a bigger value than 1) function returns carry (1) (if it has been)
basic mathematic functions
this method adding ss2 to the this and adding carry if it's defined (this = this + ss2 + c)
this method is created only on a 64bit platform***
c must be zero or one (might be a bigger value than 1) function returns carry (1) (if it was)
Definition at line 141 of file ttmathuint_noasm.h.
this method adds one *unsigned* word (at a specific position) and returns a carry (if it was)
look at a description in UInt<>::AddInt(...)
Reimplemented from UInt< value_size >.
Definition at line 236 of file ttmathint.h.
| uint AddOne | ( | ) |
this method adds one to the value and returns carry
Reimplemented from UInt< value_size >.
Definition at line 326 of file ttmathint.h.
this method adds two *unsigned* words to the existing value and these words begin on the 'index' position
index should be equal or smaller than value_size-2 (index <= value_size-2) x1 - lower word, x2 - higher word
look at a description in UInt<>::AddTwoInts(...)
Reimplemented from UInt< value_size >.
Definition at line 255 of file ttmathint.h.
this method adds two words together returns carry
this method is created only when TTMATH_NOASM macro is defined
Definition at line 105 of file ttmathuint_noasm.h.
| uint AddVector | ( | const uint * | ss1, |
| const uint * | ss2, | ||
| uint | ss1_size, | ||
| uint | ss2_size, | ||
| uint * | result | ||
| ) | [static, inherited] |
this static method addes one vector to the other 'ss1' is larger in size or equal to 'ss2'
ss1 points to the first (larger) vector ss2 points to the second vector ss1_size - size of the ss1 (and size of the result too) ss2_size - size of the ss2 result - is the result vector (which has size the same as ss1: ss1_size)
Example: ss1_size is 5, ss2_size is 3 ss1: ss2: result (output): 5 1 5+1 4 3 4+3 2 7 2+7 6 6 9 9 of course the carry is propagated and will be returned from the last item (this method is used by the Karatsuba multiplication algorithm)
Definition at line 265 of file ttmathuint_noasm.h.
| bool AreFirstBitsZero | ( | uint | bits ) | const [inherited] |
returning true if first 'bits' bits are equal zero
Definition at line 2594 of file ttmathuint.h.
| void BitAnd | ( | const UInt< value_size > & | ss2 ) | [inherited] |
this method performs a bitwise operation AND
Definition at line 743 of file ttmathuint.h.
| void BitNot | ( | ) | [inherited] |
this method performs a bitwise operation NOT
Definition at line 779 of file ttmathuint.h.
| void BitNot2 | ( | ) | [inherited] |
this method performs a bitwise operation NOT but only on the range of <0, leading_bit>
for example: BitNot2(8) = BitNot2( 1000(bin) ) = 111(bin) = 7
Definition at line 795 of file ttmathuint.h.
| void BitOr | ( | const UInt< value_size > & | ss2 ) | [inherited] |
this method performs a bitwise operation OR
Definition at line 755 of file ttmathuint.h.
| void BitXor | ( | const UInt< value_size > & | ss2 ) | [inherited] |
this method performs a bitwise operation XOR
Definition at line 767 of file ttmathuint.h.
| uint ChangeSign | ( | ) |
we change the sign of the value
if it isn't possible to change the sign this method returns 1 else return 0 and changing the sign
Definition at line 105 of file ttmathint.h.
| void ClearFirstBits | ( | uint | n ) | [inherited] |
this method sets n first bits to value zero
For example: let n=2 then if there's a value 111 (bin) there'll be '100' (bin)
Definition at line 2484 of file ttmathuint.h.
| bool CmpBigger | ( | const UInt< value_size > & | l, |
| sint | index = -1 |
||
| ) | const [inherited] |
this method returns true if 'this' is bigger than 'l'
'index' is an index of the first word from will be the comparison performed (note: we start the comparison from back - from the last word, when index is -1 /default/ it is automatically set into the last word)
I introduced it for some kind of optimization made in the second division algorithm (Div2)
Definition at line 3582 of file ttmathuint.h.
| bool CmpBiggerEqual | ( | const UInt< value_size > & | l, |
| sint | index = -1 |
||
| ) | const [inherited] |
this method returns true if 'this' is bigger than or equal 'l'
'index' is an index of the first word from will be the comparison performed (note: we start the comparison from back - from the last word, when index is -1 /default/ it is automatically set into the last word)
Definition at line 3665 of file ttmathuint.h.
| bool CmpEqual | ( | const UInt< value_size > & | l, |
| sint | index = -1 |
||
| ) | const [inherited] |
this method returns true if 'this' is equal 'l'
'index' is an index of the first word from will be the comparison performed (note: we start the comparison from back - from the last word, when index is -1 /default/ it is automatically set into the last word)
Definition at line 3610 of file ttmathuint.h.
| bool CmpSmaller | ( | const UInt< value_size > & | l, |
| sint | index = -1 |
||
| ) | const [inherited] |
methods for comparing
this method returns true if 'this' is smaller than 'l'
'index' is an index of the first word from will be the comparison performed (note: we start the comparison from back - from the last word, when index is -1 /default/ it is automatically set into the last word) I introduced it for some kind of optimization made in the second division algorithm (Div2)
Definition at line 3551 of file ttmathuint.h.
| bool CmpSmallerEqual | ( | const UInt< value_size > & | l, |
| sint | index = -1 |
||
| ) | const [inherited] |
this method returns true if 'this' is smaller than or equal 'l'
'index' is an index of the first word from will be the comparison performed (note: we start the comparison from back - from the last word, when index is -1 /default/ it is automatically set into the last word)
Definition at line 3636 of file ttmathuint.h.
| uint CompensationToLeft | ( | ) | [inherited] |
this method moves all bits into the left side (it returns value how many bits have been moved)
Definition at line 598 of file ttmathuint.h.
division this = this / ss2 returned values: 0 - ok 1 - division by zero
for example: (result means 'this') 20 / 3 --> result: 6 remainder: 2 -20 / 3 --> result: -6 remainder: -2 20 / -3 --> result: -6 remainder: 2 -20 / -3 --> result: 6 remainder: -2
in other words: this(old) = ss2 * this(new)(result) + remainder
Definition at line 479 of file ttmathint.h.
| uint Div | ( | const UInt< value_size > & | divisor, |
| UInt< value_size > * | remainder = 0, |
||
| uint | algorithm = 3 |
||
| ) | [inherited] |
division this = this / ss2
return values: 0 - ok 1 - division by zero 'this' will be the quotient 'remainder' - remainder
Definition at line 1603 of file ttmathuint.h.
the first division algorithm radix 2
Definition at line 1729 of file ttmathuint.h.
the first division algorithm radix 2
Definition at line 1752 of file ttmathuint.h.
the second division algorithm
return values: 0 - ok 1 - division by zero
Definition at line 1860 of file ttmathuint.h.
the second division algorithm
return values: 0 - ok 1 - division by zero
Definition at line 1839 of file ttmathuint.h.
the third division algorithm
Definition at line 2085 of file ttmathuint.h.
the third division algorithm
Definition at line 2102 of file ttmathuint.h.
| uint DivInt | ( | sint | ss2, |
| sint * | remainder = 0 |
||
| ) |
division this = this / ss2 (ss2 is int) returned values: 0 - ok 1 - division by zero
for example: (result means 'this') 20 / 3 --> result: 6 remainder: 2 -20 / 3 --> result: -6 remainder: -2 20 / -3 --> result: -6 remainder: 2 -20 / -3 --> result: 6 remainder: -2
in other words: this(old) = ss2 * this(new)(result) + remainder
Definition at line 523 of file ttmathint.h.
Division
division by one unsigned word
returns 1 when divisor is zero
Definition at line 1545 of file ttmathuint.h.
Division
this method calculates 64bits word a:b / 32bits c (a higher, b lower word) r = a:b / c and rest - remainder
WARNING: the c has to be suitably large for the result being keeped in one word, if c is equal zero there'll be a hardware interruption (0) and probably the end of your program
Division
this method calculates 64bits word a:b / 32bits c (a higher, b lower word) r = a:b / c and rest - remainder
WARNING: if r (one word) is too small for the result or c is equal zero there'll be a hardware interruption (0) and probably the end of your program
Division
this method calculates 64bits word a:b / 32bits c (a higher, b lower word) r = a:b / c and rest - remainder
this method is created only on a 64bit platform***
WARNING: if r (one word) is too small for the result or c is equal zero there'll be a hardware interruption (0) and probably the end of your program
Definition at line 776 of file ttmathuint_noasm.h.
this method is available only on 64bit platforms
the same algorithm like the third division algorithm in ttmathuint.h but now with the radix=2^32
Definition at line 852 of file ttmathuint_noasm.h.
this method looks for the highest set bit
result: if 'this' is not zero: return value - true 'table_id' - the index of a word <0..value_size-1> 'index' - the index of this set bit in the word <0..TTMATH_BITS_PER_UINT)
if 'this' is zero: return value - false both 'table_id' and 'index' are zero
Definition at line 649 of file ttmathuint.h.
| sint FindLeadingBitInWord | ( | uint | x ) | [static, inherited] |
this method returns the number of the highest set bit in x if the 'x' is zero this method returns '-1'
Definition at line 577 of file ttmathuint_noasm.h.
this method looks for the smallest set bit
result: if 'this' is not zero: return value - true 'table_id' - the index of a word <0..value_size-1> 'index' - the index of this set bit in the word <0..TTMATH_BITS_PER_UINT)
if 'this' is zero: return value - false both 'table_id' and 'index' are zero
Definition at line 681 of file ttmathuint.h.
| sint FindLowestBitInWord | ( | uint | x ) | [static, inherited] |
this method returns the number of the highest set bit in x if the 'x' is zero this method returns '-1'
Definition at line 600 of file ttmathuint_noasm.h.
this method converts unsigned 64 bit int type to this class this method is created only on a 32bit platform***
Reimplemented from UInt< value_size >.
Definition at line 907 of file ttmathint.h.
| uint FromInt | ( | slint | n ) |
this method converts signed 64 bit int type to this class this method is created only on a 32bit platform***
Reimplemented from UInt< value_size >.
Definition at line 917 of file ttmathint.h.
| uint FromInt | ( | unsigned int | i ) |
this method converts 32 bit unsigned int type to this class this operator is created only on a 64bit platform***
Reimplemented from UInt< value_size >.
Definition at line 1004 of file ttmathint.h.
| uint FromInt | ( | signed int | i ) |
this method converts 32 bit signed int type to this class this operator is created only on a 64bit platform***
Reimplemented from UInt< value_size >.
Definition at line 1014 of file ttmathint.h.
this method converts an Int<another_size> type into this class
this operation has mainly sense if the value from p can be held in this type
it returns a carry if the value 'p' is too big
Definition at line 696 of file ttmathint.h.
| uint FromInt | ( | sint | value ) |
this method converts the sint type into this class
Reimplemented from UInt< value_size >.
Definition at line 705 of file ttmathint.h.
this method converts UInt<another_size> into this class
Reimplemented from UInt< value_size >.
Definition at line 733 of file ttmathint.h.
this method converts the uint type into this class
Reimplemented from UInt< value_size >.
Definition at line 761 of file ttmathint.h.
| uint FromString | ( | const wchar_t * | s, |
| uint | b = 10, |
||
| const wchar_t ** | after_source = 0, |
||
| bool * | value_read = 0 |
||
| ) |
this method converts a string into its value
Reimplemented from UInt< value_size >.
Definition at line 1461 of file ttmathint.h.
this method converts a string into its value it returns carry=1 if the value will be too big or an incorrect base 'b' is given
Reimplemented from UInt< value_size >.
Definition at line 1471 of file ttmathint.h.
| uint FromString | ( | const char * | s, |
| uint | b = 10, |
||
| const char ** | after_source = 0, |
||
| bool * | value_read = 0 |
||
| ) |
this method converts a string into its value it returns carry=1 if the value will be too big or an incorrect base 'b' is given
string is ended with a non-digit value, for example: "-12" will be translated to -12 as well as: "- 12foo" will be translated to -12 too
existing first white characters will be ommited (between '-' and a first digit can be white characters too)
after_source (if exists) is pointing at the end of the parsed string
value_read (if exists) tells whether something has actually been read (at least one digit)
Reimplemented from UInt< value_size >.
Definition at line 1452 of file ttmathint.h.
this method converts a string into its value it returns carry=1 if the value will be too big or an incorrect base 'b' is given
Reimplemented from UInt< value_size >.
Definition at line 1495 of file ttmathint.h.
this method converts unsigned 64 bit int type to this class this method is created only on a 32bit platform***
Reimplemented from UInt< value_size >.
Definition at line 886 of file ttmathint.h.
| uint FromUInt | ( | unsigned int | i ) |
this method converts 32 bit unsigned int type to this class this operator is created only on a 64bit platform***
Reimplemented from UInt< value_size >.
Definition at line 994 of file ttmathint.h.
this method converts UInt<another_size> into this class
Reimplemented from UInt< value_size >.
Definition at line 723 of file ttmathint.h.
this method converts the uint type into this class
Reimplemented from UInt< value_size >.
Definition at line 742 of file ttmathint.h.
getting the 'bit_index' bit
bit_index bigger or equal zero
Definition at line 706 of file ttmathuint.h.
| bool IsOnlyTheHighestBitSet | ( | ) | const [inherited] |
returning true if only the highest bit is set
Definition at line 2541 of file ttmathuint.h.
| bool IsOnlyTheLowestBitSet | ( | ) | const [inherited] |
returning true if only the lowest bit is set
Definition at line 2565 of file ttmathuint.h.
| bool IsSign | ( | ) | const |
this method returns true if there's the sign
(the highest bit will be converted to the bool)
Definition at line 155 of file ttmathint.h.
| bool IsTheHighestBitSet | ( | ) | const [inherited] |
this method returns true if the highest bit of the value is set
Definition at line 2523 of file ttmathuint.h.
| bool IsTheLowestBitSet | ( | ) | const [inherited] |
this method returns true if the lowest bit of the value is set
Definition at line 2532 of file ttmathuint.h.
| bool IsZero | ( | ) | const [inherited] |
this method returns true if the value is equal zero
Definition at line 2581 of file ttmathuint.h.
| LibTypeCode LibType | ( | ) | [static, inherited] |
returning the currect type of the library
Definition at line 84 of file ttmathuint_noasm.h.
| const char * LibTypeStr | ( | ) | [static, inherited] |
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 66 of file ttmathuint_noasm.h.
multiplication this = this * ss2
it returns carry if the result is too big (we're using the method from the base class but we have to make one correction in account of signs)
Definition at line 439 of file ttmathint.h.
the multiplication 'this' = 'this' * ss2
algorithm: 100 - means automatically choose the fastest algorithm
Definition at line 923 of file ttmathuint.h.
multiplication: this = this * ss2 can return carry
Definition at line 1020 of file ttmathuint.h.
multiplication: result = this * ss2
result is twice bigger than 'this' and 'ss2' this method never returns carry
Definition at line 1040 of file ttmathuint.h.
the second version of the multiplication algorithm
this algorithm is similar to the 'schoolbook method' which is done by hand
multiplication: this = this * ss2
it returns carry if it has been
Definition at line 1079 of file ttmathuint.h.
multiplication: result = this * ss2
result is twice bigger than this and ss2 this method never returns carry
Definition at line 1110 of file ttmathuint.h.
multiplication: this = this * ss2
This is Karatsuba Multiplication algorithm, we're using it when value_size is greater than or equal to TTMATH_USE_KARATSUBA_MULTIPLICATION_FROM_SIZE macro (defined in ttmathuint.h). If value_size is smaller then we're using Mul2Big() instead.
Karatsuba multiplication: Assume we have: this = x = x1*B^m + x0 ss2 = y = y1*B^m + y0 where x0 and y0 are less than B^m the product from multiplication we can show as: x*y = (x1*B^m + x0)(y1*B^m + y0) = z2*B^(2m) + z1*B^m + z0 where z2 = x1*y1 z1 = x1*y0 + x0*y1 z0 = x0*y0 this is standard schoolbook algorithm with O(n^2), Karatsuba observed that z1 can be given in other form: z1 = (x1 + x0)*(y1 + y0) - z2 - z0 / z1 = (x1*y1 + x1*y0 + x0*y1 + x0*y0) - x1*y1 - x0*y0 = x1*y0 + x0*y1 / and to calculate the multiplication we need only three multiplications (with some additions and subtractions)
Our objects 'this' and 'ss2' we divide into two parts and by using recurrence we calculate the multiplication. Karatsuba multiplication has O( n^(ln(3)/ln(2)) )
Definition at line 1203 of file ttmathuint.h.
multiplication: result = this * ss2
result is twice bigger than this and ss2, this method never returns carry, (Karatsuba multiplication)
Definition at line 1236 of file ttmathuint.h.
| void MulBig | ( | const UInt< value_size > & | ss2, |
| UInt< value_size *2 > & | result, | ||
| uint | algorithm = 100 |
||
| ) | [inherited] |
the multiplication 'result' = 'this' * ss2
since the 'result' is twice bigger than 'this' and 'ss2' this method never returns a carry
algorithm: 100 - means automatically choose the fastest algorithm
Definition at line 951 of file ttmathuint.h.
multiplication this = this * ss2
Definition at line 1462 of file ttmathuint.h.
multiplication result = this * ss2
this method is trying to select the fastest algorithm (in the future this method can be improved)
Definition at line 1493 of file ttmathuint.h.
Multiplication
multiplication: this = this * ss2
it can return a carry
Definition at line 835 of file ttmathuint.h.
multiplication: result = this * ss2
we're using this method only when result_size is greater than value_size if so there will not be a carry
Definition at line 873 of file ttmathuint.h.
| uint MulInt | ( | sint | ss2 ) |
Multiplication
multiplication: result_high:result_low = a * b result_high - higher word of the result result_low - lower word of the result
this methos never returns a carry this method is used in the second version of the multiplication algorithms
multiplication: result_high:result_low = a * b result_high - higher word of the result result_low - lower word of the result
this methos never returns a carry this method is used in the second version of the multiplication algorithms
Multiplication
multiplication: result_high:result_low = a * b result_high - higher word of the result result_low - lower word of the result
this methos never returns a carry this method is used in the second version of the multiplication algorithms
this method is created only on a 64bit platform***
Definition at line 667 of file ttmathuint_noasm.h.
| UInt<value_size>& operator++ | ( | ) |
Prefix operator e.g. ++variable
Reimplemented from UInt< value_size >.
Definition at line 1766 of file ttmathint.h.
| UInt<value_size> operator++ | ( | int | ) |
Postfix operator e.g. variable++
Reimplemented from UInt< value_size >.
Definition at line 1777 of file ttmathint.h.
| Int<value_size> operator- | ( | ) | const |
standard mathematical operators
an operator for changing the sign
it's not changing 'this' but the changed value will be returned
Definition at line 1659 of file ttmathint.h.
standard mathematical operators
Definition at line 3731 of file ttmathuint.h.
| Int<value_size>& operator= | ( | const std::string & | s ) |
this operator converts a string into its value (with base = 10)
Reimplemented from UInt< value_size >.
Definition at line 1528 of file ttmathint.h.
this method converts the Uint type to this class
Reimplemented from UInt< value_size >.
Definition at line 850 of file ttmathint.h.
this operator converts an UInt<another_size> type to this class
it doesn't return a carry
Reimplemented from UInt< value_size >.
Definition at line 839 of file ttmathint.h.
| Int<value_size>& operator= | ( | unsigned int | i ) |
this method converts 32 bit unsigned int type to this class this operator is created only on a 64bit platform***
Reimplemented from UInt< value_size >.
Definition at line 1024 of file ttmathint.h.
this operator converts unsigned 64 bit int type to this class this operator is created only on a 32bit platform***
Reimplemented from UInt< value_size >.
Definition at line 944 of file ttmathint.h.
| Int<value_size>& operator= | ( | slint | n ) |
this operator converts signed 64 bit int type to this class this operator is created only on a 32bit platform***
Reimplemented from UInt< value_size >.
Definition at line 966 of file ttmathint.h.
| Int<value_size>& operator= | ( | signed int | i ) |
this operator converts 32 bit signed int type to this class this operator is created only on a 64bit platform***
Reimplemented from UInt< value_size >.
Definition at line 1046 of file ttmathint.h.
the default assignment operator
Definition at line 770 of file ttmathint.h.
this operator converts an Int<another_size> type to this class
it doesn't return a carry
Definition at line 784 of file ttmathint.h.
| Int<value_size>& operator= | ( | const char * | s ) |
this operator converts a string into its value (with base = 10)
Reimplemented from UInt< value_size >.
Definition at line 1480 of file ttmathint.h.
| Int<value_size>& operator= | ( | sint | i ) |
this method converts the sint type to this class
Reimplemented from UInt< value_size >.
Definition at line 795 of file ttmathint.h.
| Int<value_size>& operator= | ( | const wchar_t * | s ) |
this operator converts a string into its value (with base = 10)
Reimplemented from UInt< value_size >.
Definition at line 1504 of file ttmathint.h.
| Int<value_size>& operator= | ( | const std::wstring & | s ) |
this operator converts a string into its value (with base = 10)
Reimplemented from UInt< value_size >.
Definition at line 1515 of file ttmathint.h.
| bool operator== | ( | const Int< value_size > & | l ) | const |
methods for comparing
Definition at line 1544 of file ttmathint.h.
| UInt<value_size> operator~ | ( | ) | const [inherited] |
bitwise operators
Definition at line 3871 of file ttmathuint.h.
power this = this ^ pow binary algorithm (r-to-l)
return values: 0 - ok 1 - carry 2 - incorrect argument (0^0)
Definition at line 2402 of file ttmathuint.h.
power this = this ^ pow
return values: 0 - ok 1 - carry 2 - incorrect arguments 0^0 or 0^(-something)
Definition at line 607 of file ttmathint.h.
| void PrintLog | ( | const char_type * | msg, |
| ostream_type & | output | ||
| ) | const [inherited] |
this method is used when macro TTMATH_DEBUG_LOG is defined
Definition at line 159 of file ttmathuint.h.
| void PrintLog | ( | const char_type * | msg, |
| uint | carry, | ||
| ostream_type & | output | ||
| ) | const [inherited] |
this method is used when macro TTMATH_DEBUG_LOG is defined
Definition at line 169 of file ttmathuint.h.
| void PrintTable | ( | ostream_type & | output ) | const [inherited] |
some methods used for debugging purposes
this method is only for debugging purposes or when we want to make a table of a variable (constant) in ttmathbig.h
it prints the table in a nice form of several columns
Definition at line 97 of file ttmathuint.h.
| static void PrintVectorLog | ( | const char_type * | msg, |
| ostream_type & | output, | ||
| const uint * | vector, | ||
| uint | vector_len | ||
| ) | [static, inherited] |
this method is used when macro TTMATH_DEBUG_LOG is defined
Definition at line 135 of file ttmathuint.h.
| static void PrintVectorLog | ( | const char_type * | msg, |
| uint | carry, | ||
| ostream_type & | output, | ||
| const uint * | vector, | ||
| uint | vector_len | ||
| ) | [static, inherited] |
this method is used when macro TTMATH_DEBUG_LOG is defined
Definition at line 148 of file ttmathuint.h.
moving all bits into the left side 'bits' times return value <- this <- C
bits is from a range of <0, man * TTMATH_BITS_PER_UINT> or it can be even bigger then all bits will be set to 'c'
the value c will be set into the lowest bits and the method returns state of the last moved bit
Definition at line 460 of file ttmathuint.h.
moving all bits into the right side 'bits' times c -> this -> return value
bits is from a range of <0, man * TTMATH_BITS_PER_UINT> or it can be even bigger then all bits will be set to 'c'
the value c will be set into the highest bits and the method returns state of the last moved bit
Definition at line 555 of file ttmathuint.h.
setting the 'bit_index' bit and returning the last state of the bit
bit_index bigger or equal zero
Definition at line 726 of file ttmathuint.h.
this method sets a special bit in the 'value' and returns the last state of the bit (zero or one)
bit is from <0,TTMATH_BITS_PER_UINT-1>
e.g. uint x = 100; uint bit = SetBitInWord(x, 3); now: x = 108 and bit = 0
this method sets a special bit in the 'value' and returns the last state of the bit (zero or one)
bit is from <0,31> e.g. uint x = 100; uint bit = SetBitInWord(x, 3); now: x = 108 and bit = 0
this method sets a special bit in the 'value' and returns the last state of the bit (zero or one)
this method is created only on a 64bit platform***
bit is from <0,63>
e.g. uint x = 100; uint bit = SetBitInWord(x, 3); now: x = 108 and bit = 0
Definition at line 630 of file ttmathuint_noasm.h.
| void SetFromTable | ( | const unsigned int * | temp_table, |
| uint | temp_table_len | ||
| ) | [inherited] |
this method copies the value stored in an another table (warning: first values in temp_table are the highest words -- it's different from our table)
this method is created only on a 64bit platform***
we copy as many words as it is possible
if temp_table_len is bigger than value_size we'll try to round the lowest word from table depending on the last not used bit in temp_table (this rounding isn't a perfect rounding -- look at the description below)
and if temp_table_len is smaller than value_size we'll clear the rest words in the table
warning: we're using 'temp_table' as a pointer at 32bit words
Definition at line 325 of file ttmathuint.h.
this method copies the value stored in an another table (warning: first values in temp_table are the highest words -- it's different from our table)
we copy as many words as it is possible
if temp_table_len is bigger than value_size we'll try to round the lowest word from table depending on the last not used bit in temp_table (this rounding isn't a perfect rounding -- look at the description below)
and if temp_table_len is smaller than value_size we'll clear the rest words in the table
Definition at line 266 of file ttmathuint.h.
| void SetMax | ( | ) |
this method sets the max value which this class can hold (all bits will be one besides the last one)
Reimplemented from UInt< value_size >.
Definition at line 71 of file ttmathint.h.
| void SetMin | ( | ) |
this method sets the min value which this class can hold (all bits will be zero besides the last one which is one)
Reimplemented from UInt< value_size >.
Definition at line 82 of file ttmathint.h.
| void SetOne | ( | ) | [inherited] |
this method sets one
Definition at line 202 of file ttmathuint.h.
| void SetSign | ( | ) |
this method sets the sign
e.g. 1 -> -1 -2 -> -2
from a positive value we make a negative value, if the value is negative we do nothing
Definition at line 140 of file ttmathint.h.
| void SetSignOne | ( | ) |
this method sets -1 as the value (-1 is equal the max value in an unsigned type)
Definition at line 93 of file ttmathint.h.
| void SetZero | ( | ) | [inherited] |
this method sets zero
Definition at line 188 of file ttmathuint.h.
| uint Size | ( | ) | const [inherited] |
this method returns the size of the table
Definition at line 179 of file ttmathuint.h.
| void Sqrt | ( | ) | [inherited] |
square root e.g. Sqrt(9) = 3 ('digit-by-digit' algorithm)
Definition at line 2438 of file ttmathuint.h.
this method subtracts two values with a sign
we don't use the previous Add because the method ChangeSign can sometimes return carry
this = p1(=this) - p2
when p1>=0 i p2>=0 carry will never be set when p1<0 i p2<0 carry will never be set when p1>=0 i p2<0 carry is set when the highest bit of value is set when p1<0 i p2>=0 carry is set when the highest bit of value is clear
Definition at line 298 of file ttmathint.h.
this method's subtracting ss2 from the 'this' and subtracting carry if it has been defined (this = this - ss2 - c)
c must be zero or one (might be a bigger value than 1) function returns carry (1) (if it was)
subtracting ss2 from the 'this' and subtracting carry if it has been defined (this = this - ss2 - c)
c must be zero or one (might be a bigger value than 1) function returns carry (1) (if it has been)
this method's subtracting ss2 from the 'this' and subtracting carry if it has been defined (this = this - ss2 - c)
this method is created only on a 64bit platform***
c must be zero or one (might be a bigger value than 1) function returns carry (1) (if it was)
Definition at line 325 of file ttmathuint_noasm.h.
this method subtracts one *unsigned* word (at a specific position) and returns a carry (if it was)
Reimplemented from UInt< value_size >.
Definition at line 313 of file ttmathint.h.
| uint SubOne | ( | ) |
this method subtracts one from the value and returns carry
Reimplemented from UInt< value_size >.
Definition at line 339 of file ttmathint.h.
this method subtractes one word from the other returns carry
this method is created only when TTMATH_NOASM macro is defined
Definition at line 292 of file ttmathuint_noasm.h.
| uint SubVector | ( | const uint * | ss1, |
| const uint * | ss2, | ||
| uint | ss1_size, | ||
| uint | ss2_size, | ||
| uint * | result | ||
| ) | [static, inherited] |
this static method subtractes one vector from the other 'ss1' is larger in size or equal to 'ss2'
ss1 points to the first (larger) vector ss2 points to the second vector ss1_size - size of the ss1 (and size of the result too) ss2_size - size of the ss2 result - is the result vector (which has size the same as ss1: ss1_size)
Example: ss1_size is 5, ss2_size is 3 ss1: ss2: result (output): 5 1 5-1 4 3 4-3 2 7 2-7 6 6-1 (the borrow from previous item) 9 9 return (carry): 0 of course the carry (borrow) is propagated and will be returned from the last item (this method is used by the Karatsuba multiplication algorithm)
Definition at line 398 of file ttmathuint_noasm.h.
| void Swap | ( | UInt< value_size > & | ss2 ) | [inherited] |
this method swappes this for an argument
Definition at line 239 of file ttmathuint.h.
| sint ToInt | ( | ) | const |
this method returns the lowest value from table with a sign
we must be sure when we using this method whether the value will hold in an sint type or not (the rest value from table must be zero or -1)
Definition at line 1131 of file ttmathint.h.
this method converts the value to ulint type (64 bit unsigned integer) can return a carry if the value is too long to store it in ulint type this method is created only on a 32 bit platform ***
Reimplemented from UInt< value_size >.
Definition at line 1208 of file ttmathint.h.
| uint ToInt | ( | int & | result ) | const |
this method converts the value to a 32 bit signed integer can return a carry if the value is too long to store it in this type this method is created only on a 64 bit platform ***
Reimplemented from UInt< value_size >.
Definition at line 1284 of file ttmathint.h.
| uint ToInt | ( | slint & | result ) | const |
this method converts the value to slint type (64 bit signed integer) can return a carry if the value is too long to store it in slint type this method is created only on a 32 bit platform ***
Reimplemented from UInt< value_size >.
Definition at line 1219 of file ttmathint.h.
| uint ToInt | ( | unsigned int & | result ) | const |
this method converts the value to a 32 bit unsigned integer can return a carry if the value is too long to store it in this type this method is created only on a 64 bit platform ***
Reimplemented from UInt< value_size >.
Definition at line 1273 of file ttmathint.h.
this method converts the value to uint type can return a carry if the value is too long to store it in uint type
Reimplemented from UInt< value_size >.
Definition at line 1156 of file ttmathint.h.
| uint ToInt | ( | sint & | result ) | const |
this method converts the value to sint type can return a carry if the value is too long to store it in sint type
Reimplemented from UInt< value_size >.
Definition at line 1166 of file ttmathint.h.
| void ToString | ( | std::wstring & | result, |
| uint | b = 10 |
||
| ) | const |
this method converts the value to a string with a base equal 'b'
Reimplemented from UInt< value_size >.
Definition at line 1354 of file ttmathint.h.
| std::string ToString | ( | uint | b = 10 ) |
const |
this method converts the value to a string with a base equal 'b'
Reimplemented from UInt< value_size >.
Definition at line 1340 of file ttmathint.h.
| void ToString | ( | std::string & | result, |
| uint | b = 10 |
||
| ) | const |
this method converts the value to a string with a base equal 'b'
Reimplemented from UInt< value_size >.
Definition at line 1331 of file ttmathint.h.
| void ToStringBase | ( | string_type & | result, |
| uint | b = 10, |
||
| bool | negative = false |
||
| ) | const [inherited] |
an auxiliary method for converting to a string it's used from Int::ToString() too (negative is set true then)
Definition at line 3292 of file ttmathuint.h.
| double ToStringLog2 | ( | uint | x ) | const [protected, inherited] |
an auxiliary method for converting into the string it returns the log (with the base 2) from x where x is in <2;16>
Definition at line 3257 of file ttmathuint.h.
this method converts the value to uint type can return a carry if the value is too long to store it in uint type
Reimplemented from UInt< value_size >.
Definition at line 1141 of file ttmathint.h.
| uint ToUInt | ( | unsigned int & | result ) | const |
this method converts the value to a 32 bit unsigned integer can return a carry if the value is too long to store it in this type this method is created only on a 64 bit platform ***
Reimplemented from UInt< value_size >.
Definition at line 1257 of file ttmathint.h.
this method converts the value to ulint type (64 bit unsigned integer) can return a carry if the value is too long to store it in ulint type this method is created only on a 32 bit platform ***
Reimplemented from UInt< value_size >.
Definition at line 1189 of file ttmathint.h.
| uint ToUInt | ( | ) | const [inherited] |
this method returns the lowest value from table
we must be sure when we using this method whether the value will hold in an uint type or not (the rest value from the table must be zero)
Definition at line 3079 of file ttmathuint.h.
| std::wstring ToWString | ( | uint | b = 10 ) |
const |
this method converts the value to a string with a base equal 'b'
Reimplemented from UInt< value_size >.
Definition at line 1363 of file ttmathint.h.
Friends And Related Function Documentation
| std::ostream& operator<< | ( | std::ostream & | s, |
| const Int< value_size > & | l | ||
| ) | [friend] |
output to standard streams
Definition at line 1836 of file ttmathint.h.
| std::wostream& operator<< | ( | std::wostream & | s, |
| const Int< value_size > & | l | ||
| ) | [friend] |
output to standard streams
Definition at line 1847 of file ttmathint.h.
| std::wostream& operator<< | ( | std::wostream & | s, |
| const UInt< value_size > & | l | ||
| ) | [friend, inherited] |
output to standard streams
Definition at line 4015 of file ttmathuint.h.
| std::ostream& operator<< | ( | std::ostream & | s, |
| const UInt< value_size > & | l | ||
| ) | [friend, inherited] |
output to standard streams
Definition at line 4004 of file ttmathuint.h.
| std::istream& operator>> | ( | std::istream & | s, |
| UInt< value_size > & | l | ||
| ) | [friend, inherited] |
input from standard streams
Definition at line 4062 of file ttmathuint.h.
| std::wistream& operator>> | ( | std::wistream & | s, |
| Int< value_size > & | l | ||
| ) | [friend] |
input from standard streams
Definition at line 1911 of file ttmathint.h.
| std::wistream& operator>> | ( | std::wistream & | s, |
| UInt< value_size > & | l | ||
| ) | [friend, inherited] |
input from standard streams
Definition at line 4073 of file ttmathuint.h.
| std::istream& operator>> | ( | std::istream & | s, |
| Int< value_size > & | l | ||
| ) | [friend] |
input from standard streams
Definition at line 1900 of file ttmathint.h.
Field Documentation
buffer for the integer value table[0] - the lowest word of the value
Definition at line 81 of file ttmathuint.h.
Generated on Tue Jul 12 2022 14:03:18 by
1.7.2